Skip to content

Commit

Permalink
Update metadatav10 (#51)
Browse files Browse the repository at this point in the history
* Add support for metadata v10

* Fix linting errors
  • Loading branch information
philipstanislaus authored and vedhavyas committed Jan 17, 2020
1 parent b277fcc commit 4dc63dc
Show file tree
Hide file tree
Showing 11 changed files with 762 additions and 50 deletions.
14 changes: 7 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ run:
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- types/metadata_examplary.go
- types/metadataV[0-9]+_examplary.go
# - ".*\\.my\\.go$"
# - lib/bad.go

Expand Down Expand Up @@ -114,6 +114,12 @@ issues:
- path: types/uint.go
linters:
- dupl
- path: types/metadataV8.go
linters:
- dupl
- path: types/metadataV10.go
linters:
- dupl
- path: types/option_int.go
linters:
- dupl
Expand All @@ -126,12 +132,6 @@ issues:
- path: types/storage_data_raw_test.go
linters:
- dupl
- path: types/metadata_examplary.go
text: ".*"
# linters:
# - dupl
# - golint
# - misspell
- path: doc.go
linters:
- lll
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ run-substrate-docker: ## runs the Substrate 1.0 Default Docker image, this can
docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 parity/substrate:latest-v1.0 --dev --rpc-external --ws-external

run-substrate-docker-v2: ## runs the Substrate 2.0 Default Docker image, this can be used to run the tests
docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 parity/substrate:2.0.0-5dece71 --dev --rpc-external --ws-external
docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 parity/substrate:2.0.0-ddb309ae --dev --rpc-external --ws-external

help: ## shows this help
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST)
Expand Down
37 changes: 27 additions & 10 deletions types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ const MagicNumber uint32 = 0x6174656d
// Modelled after https://github.com/paritytech/substrate/blob/v1.0.0rc2/srml/metadata/src/lib.rs

type Metadata struct {
MagicNumber uint32
Version uint8
IsMetadataV4 bool
AsMetadataV4 MetadataV4
IsMetadataV7 bool
AsMetadataV7 MetadataV7
IsMetadataV8 bool
AsMetadataV8 MetadataV8
IsMetadataV9 bool
AsMetadataV9 MetadataV9
MagicNumber uint32
Version uint8
IsMetadataV4 bool
AsMetadataV4 MetadataV4
IsMetadataV7 bool
AsMetadataV7 MetadataV7
IsMetadataV8 bool
AsMetadataV8 MetadataV8
IsMetadataV9 bool
AsMetadataV9 MetadataV9
IsMetadataV10 bool
AsMetadataV10 MetadataV10
}

func NewMetadataV4() *Metadata {
Expand All @@ -55,6 +57,10 @@ func NewMetadataV9() *Metadata {
return &Metadata{Version: 9, IsMetadataV9: true, AsMetadataV9: MetadataV9{make([]ModuleMetadataV8, 0)}}
}

func NewMetadataV10() *Metadata {
return &Metadata{Version: 10, IsMetadataV10: true, AsMetadataV10: MetadataV10{make([]ModuleMetadataV10, 0)}}
}

func (m *Metadata) Decode(decoder scale.Decoder) error {
err := decoder.Decode(&m.MagicNumber)
if err != nil {
Expand Down Expand Up @@ -82,6 +88,9 @@ func (m *Metadata) Decode(decoder scale.Decoder) error {
case 9:
m.IsMetadataV9 = true
err = decoder.Decode(&m.AsMetadataV9)
case 10:
m.IsMetadataV10 = true
err = decoder.Decode(&m.AsMetadataV10)
default:
return fmt.Errorf("unsupported metadata version %v", m.Version)
}
Expand Down Expand Up @@ -109,6 +118,8 @@ func (m Metadata) Encode(encoder scale.Encoder) error {
err = encoder.Encode(m.AsMetadataV8)
case 9:
err = encoder.Encode(m.AsMetadataV9)
case 10:
err = encoder.Encode(m.AsMetadataV10)
default:
return fmt.Errorf("unsupported metadata version %v", m.Version)
}
Expand All @@ -126,6 +137,8 @@ func (m *Metadata) FindCallIndex(call string) (CallIndex, error) {
return m.AsMetadataV8.FindCallIndex(call)
case m.IsMetadataV9:
return m.AsMetadataV9.FindCallIndex(call)
case m.IsMetadataV10:
return m.AsMetadataV10.FindCallIndex(call)
default:
return CallIndex{}, fmt.Errorf("unsupported metadata version")
}
Expand All @@ -141,6 +154,8 @@ func (m *Metadata) FindEventNamesForEventID(eventID EventID) (Text, Text, error)
return m.AsMetadataV8.FindEventNamesForEventID(eventID)
case m.IsMetadataV9:
return m.AsMetadataV9.FindEventNamesForEventID(eventID)
case m.IsMetadataV10:
return m.AsMetadataV10.FindEventNamesForEventID(eventID)
default:
return "", "", fmt.Errorf("unsupported metadata version")
}
Expand All @@ -156,6 +171,8 @@ func (m *Metadata) FindStorageEntryMetadata(module string, fn string) (StorageEn
return m.AsMetadataV8.FindStorageEntryMetadata(module, fn)
case m.IsMetadataV9:
return m.AsMetadataV9.FindStorageEntryMetadata(module, fn)
case m.IsMetadataV10:
return m.AsMetadataV10.FindStorageEntryMetadata(module, fn)
default:
return nil, fmt.Errorf("unsupported metadata version")
}
Expand Down
Loading

0 comments on commit 4dc63dc

Please sign in to comment.