88use Casper \Serializer \CLPublicKeySerializer ;
99use Casper \Serializer \CLURefSerializer ;
1010use Casper \Serializer \EraSummarySerializer ;
11+ use Casper \Serializer \GlobalStateSerializer ;
1112use Casper \Serializer \PeerSerializer ;
1213use Casper \Serializer \BlockSerializer ;
1314use Casper \Serializer \DeploySerializer ;
2425use Casper \Entity \Block ;
2526use Casper \Entity \Deploy ;
2627use Casper \Entity \EraSummary ;
28+ use Casper \Entity \GlobalState ;
2729use Casper \Entity \Peer ;
2830use Casper \Entity \Status ;
2931use Casper \Entity \StoredValue ;
@@ -50,6 +52,7 @@ class RpcClient
5052 private const RPC_METHOD_GET_ACCOUNT_BALANCE = 'state_get_balance ' ;
5153 private const RPC_METHOD_GET_ERA_INFO_BY_SWITCH_BLOCK = 'chain_get_era_info_by_switch_block ' ;
5254 private const RPC_METHOD_GET_DICTIONARY_ITEM = 'state_get_dictionary_item ' ;
55+ private const RPC_METHOD_QUERY_GLOBAL_STATE = 'query_global_state ' ;
5356
5457 private string $ nodeUrl ;
5558
@@ -348,6 +351,41 @@ public function getDictionaryItemByURef(
348351 return StoredValueSerializer::fromJson ($ response ['stored_value ' ]);
349352 }
350353
354+ /**
355+ * @throws RpcError
356+ */
357+ public function getGlobalStateByBlock (string $ blockHash , string $ key , array $ path = []): GlobalState
358+ {
359+ $ response = $ this ->rpcCallMethod (
360+ self ::RPC_METHOD_QUERY_GLOBAL_STATE ,
361+ array (
362+ 'state_identifier ' => array (
363+ 'BlockHash ' => $ blockHash
364+ ),
365+ 'key ' => $ key ,
366+ 'path ' => $ path ,
367+ )
368+ );
369+
370+ return GlobalStateSerializer::fromJson ($ response );
371+ }
372+
373+ public function getGlobalStateByStateRootHash (string $ stateRootHash , string $ key , array $ path = []): GlobalState
374+ {
375+ $ response = $ this ->rpcCallMethod (
376+ self ::RPC_METHOD_QUERY_GLOBAL_STATE ,
377+ array (
378+ 'state_identifier ' => array (
379+ 'StateRootHash ' => $ stateRootHash
380+ ),
381+ 'key ' => $ key ,
382+ 'path ' => $ path ,
383+ )
384+ );
385+
386+ return GlobalStateSerializer::fromJson ($ response );
387+ }
388+
351389 /**
352390 * @throws RpcError
353391 */
0 commit comments