Get storage API, with storage leaf CID and raw IPLD block.
This commit is contained in:
committed by
Arijit Das
parent
b90fcb53e6
commit
a284a566d5
+37
-2
@@ -956,12 +956,47 @@ func (r *Resolver) Logs(ctx context.Context, args struct{ Filter FilterCriteria
|
||||
return runFilter(ctx, r.backend, filter)
|
||||
}
|
||||
|
||||
// StorageResult represents a storage slot value. All arguments are mandatory.
|
||||
type StorageResult struct {
|
||||
value []byte
|
||||
cid string
|
||||
ipldBlock []byte
|
||||
}
|
||||
|
||||
func (s *StorageResult) Value(ctx context.Context) common.Hash {
|
||||
return common.BytesToHash(s.value)
|
||||
}
|
||||
|
||||
func (s *StorageResult) Cid(ctx context.Context) string {
|
||||
return s.cid
|
||||
}
|
||||
|
||||
func (s *StorageResult) IpldBlock(ctx context.Context) hexutil.Bytes {
|
||||
return hexutil.Bytes(s.ipldBlock)
|
||||
}
|
||||
|
||||
func (r *Resolver) GetStorageAt(ctx context.Context, args struct {
|
||||
BlockHash common.Hash
|
||||
Contract common.Address
|
||||
Slot common.Hash
|
||||
}) (*common.Hash, error) {
|
||||
ret := common.BytesToHash([]byte{})
|
||||
}) (*StorageResult, error) {
|
||||
cid, ipldBlock, rlpValue, err := r.backend.IPLDRetriever.RetrieveStorageAtByAddressAndStorageKeyAndBlockHash(args.Contract, args.Slot, args.BlockHash)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var value interface{}
|
||||
err = rlp.DecodeBytes(rlpValue, &value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := StorageResult{value: value.([]byte), cid: cid, ipldBlock: ipldBlock}
|
||||
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
+12
-1
@@ -265,6 +265,17 @@ const schema string = `
|
||||
topics: [[Bytes32!]!]
|
||||
}
|
||||
|
||||
# Storage trie value with IPLD data.
|
||||
type StorageResult {
|
||||
value: Bytes32!
|
||||
|
||||
# CID for the storage trie IPLD block.
|
||||
cid: String!
|
||||
|
||||
# Storage trie IPLD block.
|
||||
ipldBlock: Bytes!
|
||||
}
|
||||
|
||||
type Query {
|
||||
# Block fetches an Ethereum block by number or by hash. If neither is
|
||||
# supplied, the most recent known block is returned.
|
||||
@@ -281,7 +292,7 @@ const schema string = `
|
||||
logs(filter: FilterCriteria!): [Log!]!
|
||||
|
||||
# Get storage slot by block hash and contract address.
|
||||
getStorageAt(blockHash: Bytes32!, contract: Address!, slot: Bytes32!): Bytes32
|
||||
getStorageAt(blockHash: Bytes32!, contract: Address!, slot: Bytes32!): StorageResult
|
||||
|
||||
# Get contract logs by block hash and contract address.
|
||||
getLogs(blockHash: Bytes32!, contract: Address!): [Log!]
|
||||
|
||||
Reference in New Issue
Block a user