itering / scale.go

Golang polkadot substrate scale codec
http://subscan.io
Apache License 2.0
63 stars 36 forks source link

value_id is always 0 #67

Closed ioannist closed 2 years ago

ioannist commented 2 years ago

The program below returns storage entries for the Balance pallet. It looks like value_id is always 0

import (
    "encoding/json"
    "fmt"

    "github.com/itering/substrate-api-rpc/metadata"
    "github.com/itering/substrate-api-rpc/rpc"
    "github.com/itering/substrate-api-rpc/websocket"
)

func main() {
    websocket.SetEndpoint("wss://rpc.polkadot.io/")
    wsConn, err := websocket.Init()
    fmt.Printf("websocket: %v\n", err)
    blockHash := "0x0943b15cf71fdc56721a4c410c7a741130b2d58ef3635460482ef77032616308"
    result, err := rpc.GetMetadataByHash(wsConn.Conn, blockHash)
    instant := metadata.Latest(&metadata.RuntimeRaw{Spec: -1, Raw: result})

    for _, module := range instant.Metadata.Modules {
        for _, storage := range module.Storage {
            if module.Name == "Balances" {
                fmt.Println(storage.Name)
                b, err := json.MarshalIndent(storage.Type.NMapType, "", "  ")
                if err != nil {
                    fmt.Println("error:", err)
                }
                fmt.Println(string(b))
            }
        }
    }
}

Observed output

TotalIssuance
null
Account
{
  "hashers": [
    "Blake2_128Concat"
  ],
  "key_vec": [
    "[U8; 32]"
  ],
  "value": "pallet_balances:AccountData",
  "keys_id": 0,
  "value_id": 0
}
Locks
{
  "hashers": [
    "Blake2_128Concat"
  ],
  "key_vec": [
    "[U8; 32]"
  ],
  "value": "Vec\u003cpallet_balances:BalanceLock\u003e",
  "keys_id": 0,
  "value_id": 0
}
Reserves
{
  "hashers": [
    "Blake2_128Concat"
  ],
  "key_vec": [
    "[U8; 32]"
  ],
  "value": "Vec\u003cpallet_balances:ReserveData\u003e",
  "keys_id": 0,
  "value_id": 0
}
StorageVersion
null

Expected output: value_id should be 5 for Account, i.e. directly from polkadot.js.org metadata:

name: Account
modifier: Default
type: {
  Map: {
    hashers: [
      Blake2_128Concat
    ]
    key: 0
    value: 5
  }
}
freehere107 commented 2 years ago

@ioannist Thank you feedback, this issue has been fixed.