Query Api

QueryApi는 조회를 위한 high-level api를 제공합니다. 별도의 unlock된 계정이 필요하지 않습니다.

Get Account State

계정의 상태 조회.

// get account state
AccountAddress accountAddress = AccountAddress
    .of("AmNrsAqkXhQfE6sGxTutQkf9ekaYowaJFLekEm8qvDr1RB1AnsiM");
AccountState state = walletApi.with(client).query()
    .getAccountState(accountAddress);
System.out.println("Account state: " + state);

Get Name Owner

이름의 소유 계정을 조회합니다.

현재 블록 기준으로 조회합니다.

// get name owner
Name name = Name.of("namenamename");
AccountAddress nameOwner = walletApi.with(client).query().getNameOwner(name);
System.out.println("Name owner: " + nameOwner);

특정 블록 기준으로 조회합니다.

// get name owner at block 10
Name name = Name.of("namenamename");
AccountAddress nameOwner = walletApi.with(client).query().getNameOwner(name, 10);
System.out.println("Name owner: " + nameOwner);

Get Stake Info

계정의 staking 정보를 조회합니다.

// get stake info
AccountAddress accountAddress = AccountAddress
    .of("AmNrsAqkXhQfE6sGxTutQkf9ekaYowaJFLekEm8qvDr1RB1AnsiM");
StakeInfo stakeInfo = walletApi.with(client).query().getStakeInfo(accountAddress);
System.out.println("Stake info: " + stakeInfo);

List Elected Bps

Block producers로 선정된 후보 노드들을 조회합니다.

// list elected bps
List<ElectedCandidate> candidates = walletApi.with(client).query().listElectedBps(23);
System.out.println("Elected bps: " + candidates);

List Elected

Vote id에 해당되는 투표 결과를 조회합니다.

// list elected for "voteBP"
List<ElectedCandidate> candidates = walletApi.with(client).query()
    .listElected("voteBP", 23);
System.out.println("Elected candidates: " + candidates);

Get Vote Info

계정의 투표 정보를 조회합니다.

// get vote info
AccountAddress accountAddress = AccountAddress
    .of("AmNrsAqkXhQfE6sGxTutQkf9ekaYowaJFLekEm8qvDr1RB1AnsiM");
AccountTotalVote accountTotalVote = walletApi.with(client).query().getVotesOf(accountAddress);
System.out.println("Account total vote: " + accountTotalVote);

Get Best Block Hash

현재 node의 최고 블록의 해쉬를 조회합니다.

// get best block hash
BlockHash blockHash = walletApi.with(client).query().getBestBlockHash();
System.out.println("Best block hash: " + blockHash);

Get Best Block Height

현재 node의 최고 블록의 높이를 조회합니다.

// get best block hash
long blockHeight = walletApi.with(client).query().getBestBlockHeight();
System.out.println("Best block height: " + blockHeight);

Get Chain Id Hash

현재 연결되어 있는 node의 chain id hash를 조회합니다.

// get chain id hash
ChainIdHash chainIdHash = walletApi.with(client).query().getChainIdHash();
System.out.println("Chain id hash: " + chainIdHash);

Get Blockchain Status

현재 연결되어 있는 node의 blockchain 상태를 조회합니다.

// get blockchain status
BlockchainStatus blockchainStatus = walletApi.with(client).query().getBlockchainStatus();
System.out.println("Blockchain status: " + blockchainStatus);

Get Chain Info

현재 연결되어 있는 node의 chain 정보를 조회합니다.

// get chain info
ChainInfo chainInfo = walletApi.with(client).query().getChainInfo();
System.out.println("ChainInfo: " + chainInfo);

Get Chain Stats

현재 연결되어 있는 node의 chain 상태를 조회합니다.

// get chain stats
ChainStats chainStats = walletApi.with(client).query().getChainStats();
System.out.println("ChainStats: " + chainStats);

List Peers

현재 연결되어 있는 node의 peer정보를 조회합니다.

자기 자신과 hidden peer를 제외하고 조회합니다.

// list peers
List<Peer> peers = walletApi.with(client).query().listPeers();
System.out.println("Peers: " + peers);

자기 자신과 hidden peer를 제외하지 않고 조회합니다.

// list peers
List<Peer> peers = walletApi.with(client).query().listPeers(true, true);
System.out.println("Peers: " + peers);

List Peer Metrics

현재 연결되어 있는 node의 peer 상태를 조회합니다.

// list peer metrics
List<PeerMetric> peerMetrics = walletApi.with(client).query().listPeerMetrics();
System.out.println("Peer metrics: " + peerMetrics);

Get Server Info

현재 연결되어 있는 node의 서버 정보를 조회합니다. Category는 아직 구현되어 있지 않습니다.

// get server info
List<String> categories = emptyList();
ServerInfo serverInfo = walletApi.with(client).query().getServerInfo(categories);
System.out.println("Server info: " + serverInfo);

Get Node Status

현재 연결되어 있는 node자체의 상태를 조회합니다.

// get node status
NodeStatus nodeStatus = walletApi.with(client).query().getNodeStatus();
System.out.println("Node status: " + nodeStatus);

Get Block Metadata

Block의 메타정보를 조회합니다. 해당되는 정보가 없는 경우 null을 리턴합니다.

해쉬를 사용해서 조회.

// get block metadata
BlockHash blockHash = BlockHash.of("DN9TvryaThbJneSpzaXp5ZsS4gE3UMzKfaXC4x8L5qR1");
BlockMetadata blockMetadata = walletApi.with(client).query().getBlockMetadata(blockHash);
System.out.println("Block metadata by hash: " + blockMetadata);

높이를 사용해서 조회.

// get block metadata
long height = 27_066_653L;
BlockMetadata blockMetadata = walletApi.with(client).query().getBlockMetadata(height);
System.out.println("Block metadata by height: " + blockMetadata);

List Block Metadata

Block의 메타정보들을 조회합니다. 한번에 조회할 수 있는 최고 크기는 1000입니다.

해쉬를 사용해서 조회.

// block metadatas by from hash to previous 100 block
BlockHash blockHash = BlockHash.of("DN9TvryaThbJneSpzaXp5ZsS4gE3UMzKfaXC4x8L5qR1");
List<BlockMetadata> blockMetadatas = walletApi.with(client).query()
    .listBlockMetadatas(blockHash, 100);
System.out.println("Block metadatas by hash: " + blockMetadatas);

높이를 사용해서 조회.

// block metadatas by from height to previous 100 block
long height = 27_066_653L;
List<BlockMetadata> blockMetadatas = walletApi.with(client).query()
    .listBlockMetadatas(height, 100);
System.out.println("Block metadatas by height: " + blockMetadatas);

Get Block

Block정보를 조회합니다. 해당되는 정보가 없을 경우 null을 리턴합니다.

해쉬를 사용해서 조회.

// get block by hash
BlockHash blockHash = BlockHash.of("DN9TvryaThbJneSpzaXp5ZsS4gE3UMzKfaXC4x8L5qR1");
Block block = walletApi.with(client).query().getBlock(blockHash);
System.out.println("Block by hash: " + block);

높이를 사용해서 조회.

// get block by height
long height = 27_066_653L;
Block block = walletApi.with(client).query().getBlock(height);
System.out.println("Block by hash: " + block);

Block Metadata Subscription

새롭게 생성된 Block 메타정보를 구독합니다.

// make a subscription
Subscription<BlockMetadata> metadataSubscription = walletApi.with(client).query()
    .subscribeBlockMetadata(new StreamObserver<BlockMetadata>() {
      @Override
      public void onNext(BlockMetadata value) {
        System.out.println("Next block metadata: " + value);
      }

      @Override
      public void onError(Throwable t) {

      }

      @Override
      public void onCompleted() {
      }
    });

// wait for a while
Thread.sleep(2000L);

// unsubscribe it
metadataSubscription.unsubscribe();

Block Subscription

새롭게 생성된 Block 정보를 구독합니다.

// make a subscription
Subscription<Block> subscription = walletApi.with(client).query()
    .subscribeBlock(new StreamObserver<Block>() {
      @Override
      public void onNext(Block value) {
        System.out.println("Next block: " + value);
      }

      @Override
      public void onError(Throwable t) {
      }

      @Override
      public void onCompleted() {
      }
    });

// wait for a while
Thread.sleep(2000L);

// unsubscribe it
subscription.unsubscribe();

Get Transaction

Transaction 정보를 조회합니다. 해당되는 정보가 없을 경우 null을 리턴합니다.

// get transaction
TxHash txHash = TxHash.of("39vLyMqsg1mTT9mF5NbADgNB2YUiRVsT6SUkDujBZme8");
Transaction transaction = walletApi.with(client).query().getTransaction(txHash);
System.out.println("Transaction: " + transaction);

Get Transaction Receipt

Transaction의 영수증을 조회합니다. 해당되는 정보가 없을 경우 null을 리턴합니다.

// get tx receipt
TxHash txHash = TxHash.of("39vLyMqsg1mTT9mF5NbADgNB2YUiRVsT6SUkDujBZme8");
TxReceipt txReceipt = walletApi.with(client).query().getTxReceipt(txHash);
System.out.println("Transaction receipt: " + txReceipt);

Get Contract Tx Receipt

contract tx에 대한 영수증을 조회합니다. 해당되는 정보가 없을 경우 null을 리턴합니다.

// get contract tx receipt
TxHash txHash = TxHash.of("EGXNDgjY2vQ6uuP3UF3dNXud54dF4FNVY181kaeQ26H9");
ContractTxReceipt contractTxReceipt = walletApi.with(client).query()
    .getContractTxReceipt(txHash);
System.out.println("Contract tx receipt: " + contractTxReceipt);

Get Contract Interface

contract에 대한 interface를 조회합니다. 해당되는 정보가 없을 경우 null을 리턴합니다.

// get contract interface
ContractAddress contractAddress = ContractAddress
    .of("AmNrsAqkXhQfE6sGxTutQkf9ekaYowaJFLekEm8qvDr1RB1AnsiM");
ContractInterface contractInterface = walletApi.with(client).query()
    .getContractInterface(contractAddress);
System.out.println("ContractInterface: " + contractInterface);

Query Contract

배포되어 있는 contract의 상태를 조회합니다. Contract invocation에 대해 더 자세히 알고 싶으시면 다음의 문서를 참고하세요 ContractInvocation.

// make a contract invocation
ContractInterface contractInterface = contractInterfaceKeep;
ContractInvocation query = contractInterface.newInvocationBuilder()
    .function("get")
    .args("key")
    .build();

// query contract
ContractResult queryResult = client.getContractOperation().query(query);
Data data = queryResult.bind(Data.class);
System.out.println("Raw contract result: " + queryResult);
System.out.println("Binded data: " + data);

List Event

특정 block에 발생한 event정보를 조회합니다. Event filter에 대해 더 자세히 알고 싶으시면 다음의 문서를 참고하세요 EventFilter.

// list events with a filter
ContractAddress contractAddress = contractAddressKeep;
EventFilter eventFilter = EventFilter.newBuilder(contractAddress)
    .eventName("set")
    .args("key")
    .recentBlockCount(1000)
    .build();
List<Event> events = client.getContractOperation().listEvents(eventFilter);
System.out.println("Events: " + events);

Event Subscription

새롭게 발행하는 event정보를 구독합니다. Event filter에 대해 더 자세히 알고 싶으시면 다음의 문서를 참고하세요 EventFilter.

// subscribe event
ContractAddress contractAddress = ContractAddress
    .of("AmNrsAqkXhQfE6sGxTutQkf9ekaYowaJFLekEm8qvDr1RB1AnsiM");
EventFilter eventFilter = EventFilter.newBuilder(contractAddress)
    .recentBlockCount(1000)
    .build();
Subscription<Event> subscription = client.getContractOperation()
    .subscribeEvent(eventFilter, new StreamObserver<Event>() {
      @Override
      public void onNext(Event value) {
        System.out.println("Next event: " + value);
      }

      @Override
      public void onError(Throwable t) {
      }

      @Override
      public void onCompleted() {
      }
    });

Thread.sleep(2200L);

// unsubscribe event
subscription.unsubscribe();