-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add metadata V12 * FIX AccountInfo Refcount should be unsigned 32 (see paritytech/substrate#7164) * FIX Use Module index when looking for Call index * FIX Use released v2.0.0 substrate version * FIX Goimports types/metadataV12.go * FIX Add some unit tests * Remove run-substrate-docker v1 makefile target. Co-authored-by: Laurent Turek <[email protected]>
- Loading branch information
1 parent
305d63b
commit 3e97443
Showing
10 changed files
with
389 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/centrifuge/go-substrate-rpc-client/scale" | ||
) | ||
|
||
// Modelled after packages/types/src/Metadata/v11/toV12.ts | ||
type MetadataV12 struct { | ||
Modules []ModuleMetadataV12 | ||
Extrinsic ExtrinsicV11 | ||
} | ||
|
||
func (m *MetadataV12) Decode(decoder scale.Decoder) error { | ||
err := decoder.Decode(&m.Modules) | ||
if err != nil { | ||
return err | ||
} | ||
return decoder.Decode(&m.Extrinsic) | ||
} | ||
|
||
func (m MetadataV12) Encode(encoder scale.Encoder) error { | ||
err := encoder.Encode(m.Modules) | ||
if err != nil { | ||
return err | ||
} | ||
return encoder.Encode(m.Extrinsic) | ||
} | ||
|
||
func (m *MetadataV12) FindCallIndex(call string) (CallIndex, error) { | ||
s := strings.Split(call, ".") | ||
for _, mod := range m.Modules { | ||
if !mod.HasCalls { | ||
continue | ||
} | ||
if string(mod.Name) != s[0] { | ||
continue | ||
} | ||
for ci, f := range mod.Calls { | ||
if string(f.Name) == s[1] { | ||
return CallIndex{mod.Index, uint8(ci)}, nil | ||
} | ||
} | ||
return CallIndex{}, fmt.Errorf("method %v not found within module %v for call %v", s[1], mod.Name, call) | ||
} | ||
return CallIndex{}, fmt.Errorf("module %v not found in metadata for call %v", s[0], call) | ||
} | ||
|
||
func (m *MetadataV12) FindEventNamesForEventID(eventID EventID) (Text, Text, error) { | ||
for _, mod := range m.Modules { | ||
if !mod.HasEvents { | ||
continue | ||
} | ||
if mod.Index != eventID[0] { | ||
continue | ||
} | ||
if int(eventID[1]) >= len(mod.Events) { | ||
return "", "", fmt.Errorf("event index %v for module %v out of range", eventID[1], mod.Name) | ||
} | ||
return mod.Name, mod.Events[eventID[1]].Name, nil | ||
} | ||
return "", "", fmt.Errorf("module index %v out of range", eventID[0]) | ||
} | ||
|
||
func (m *MetadataV12) FindStorageEntryMetadata(module string, fn string) (StorageEntryMetadata, error) { | ||
for _, mod := range m.Modules { | ||
if !mod.HasStorage { | ||
continue | ||
} | ||
if string(mod.Storage.Prefix) != module { | ||
continue | ||
} | ||
for _, s := range mod.Storage.Items { | ||
if string(s.Name) != fn { | ||
continue | ||
} | ||
return s, nil | ||
} | ||
return nil, fmt.Errorf("storage %v not found within module %v", fn, module) | ||
} | ||
return nil, fmt.Errorf("module %v not found in metadata", module) | ||
} | ||
|
||
func (m *MetadataV12) ExistsModuleMetadata(module string) bool { | ||
for _, mod := range m.Modules { | ||
if string(mod.Name) == module { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
type ModuleMetadataV12 struct { | ||
Name Text | ||
HasStorage bool | ||
Storage StorageMetadataV10 | ||
HasCalls bool | ||
Calls []FunctionMetadataV4 | ||
HasEvents bool | ||
Events []EventMetadataV4 | ||
Constants []ModuleConstantMetadataV6 | ||
Errors []ErrorMetadataV8 | ||
Index uint8 | ||
} | ||
|
||
func (m *ModuleMetadataV12) Decode(decoder scale.Decoder) error { | ||
err := decoder.Decode(&m.Name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = decoder.Decode(&m.HasStorage) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.HasStorage { | ||
err = decoder.Decode(&m.Storage) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = decoder.Decode(&m.HasCalls) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.HasCalls { | ||
err = decoder.Decode(&m.Calls) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = decoder.Decode(&m.HasEvents) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.HasEvents { | ||
err = decoder.Decode(&m.Events) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = decoder.Decode(&m.Constants) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = decoder.Decode(&m.Errors) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return decoder.Decode(&m.Index) | ||
} | ||
|
||
func (m ModuleMetadataV12) Encode(encoder scale.Encoder) error { | ||
err := encoder.Encode(m.Name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = encoder.Encode(m.HasStorage) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.HasStorage { | ||
err = encoder.Encode(m.Storage) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = encoder.Encode(m.HasCalls) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.HasCalls { | ||
err = encoder.Encode(m.Calls) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = encoder.Encode(m.HasEvents) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.HasEvents { | ||
err = encoder.Encode(m.Events) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = encoder.Encode(m.Constants) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = encoder.Encode(m.Errors) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return encoder.Encode(m.Index) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.