Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
Add default support to storage returns
Browse files Browse the repository at this point in the history
  • Loading branch information
wuminzhe committed May 28, 2021
1 parent 627a17f commit 87e42dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def generate_storage_key_from_metadata(metadata, module_name, storage_name, para
hasher2,
metadata.value.value[:metadata][:version]
)
[storage_key, return_type]
storage_modifier = storage_item[:modifier]
[storage_key, return_type, storage_item]
end

def generate_storage_key(module_name, storage_name, params = nil, hasher = nil, hasher2 = nil, metadata_version = nil)
Expand Down
7 changes: 5 additions & 2 deletions lib/substrate_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ def get_block_events(block_hash=nil)
def get_storage(module_name, storage_name, params = nil, block_hash = nil)
self.init_types_and_metadata(block_hash)

storage_key, return_type = SubstrateClient::Helper.generate_storage_key_from_metadata(@metadata, module_name, storage_name, params)
storage_key, return_type, storage_item = SubstrateClient::Helper.generate_storage_key_from_metadata(@metadata, module_name, storage_name, params)
data = self.state_getStorage(storage_key, block_hash)
return unless data

if data.nil? && storage_item[:modifier] == "Default" && (not storage_item[:fallback].nil?)
data = storage_item[:fallback]
end

bytes = Scale::Bytes.new(data)
type = Scale::Types.get(return_type)
Expand Down

0 comments on commit 87e42dc

Please sign in to comment.