Search in sources :

Example 1 with NodeAddressBook

use of com.hedera.hashgraph.sdk.NodeAddressBook in project hedera-sdk-java by hashgraph.

the class GetAddressBookExample method main.

public static void main(String[] args) throws PrecheckStatusException, IOException, TimeoutException {
    Client client = Client.forName(HEDERA_NETWORK);
    // Defaults the operator account ID and key such that all generated transactions will be paid for
    // by this account and be signed by this key
    client.setOperator(OPERATOR_ID, OPERATOR_KEY);
    FileContentsQuery fileQuery = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK);
    Hbar cost = fileQuery.getCost(client);
    System.out.println("file contents cost: " + cost);
    fileQuery.setMaxQueryPayment(new Hbar(1));
    ByteString contents = fileQuery.execute(client);
    Files.deleteIfExists(FileSystems.getDefault().getPath("address-book.proto.bin"));
    Files.copy(new ByteArrayInputStream(contents.toByteArray()), FileSystems.getDefault().getPath("address-book.proto.bin"));
    // NEW (Feb 25 2022): you can now fetch the address book for free from a mirror node with AddressBookQuery
    NodeAddressBook addressBook = new AddressBookQuery().setFileId(FileId.ADDRESS_BOOK).execute(client);
    System.out.println(addressBook);
}
Also used : FileContentsQuery(com.hedera.hashgraph.sdk.FileContentsQuery) AddressBookQuery(com.hedera.hashgraph.sdk.AddressBookQuery) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteString(com.google.protobuf.ByteString) NodeAddressBook(com.hedera.hashgraph.sdk.NodeAddressBook) Hbar(com.hedera.hashgraph.sdk.Hbar) Client(com.hedera.hashgraph.sdk.Client)

Aggregations

ByteString (com.google.protobuf.ByteString)1 AddressBookQuery (com.hedera.hashgraph.sdk.AddressBookQuery)1 Client (com.hedera.hashgraph.sdk.Client)1 FileContentsQuery (com.hedera.hashgraph.sdk.FileContentsQuery)1 Hbar (com.hedera.hashgraph.sdk.Hbar)1 NodeAddressBook (com.hedera.hashgraph.sdk.NodeAddressBook)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1