Skip to content

Commit

Permalink
Merge pull request #2 from Platdot-network/meta-v14
Browse files Browse the repository at this point in the history
Support metadata v14
  • Loading branch information
hacpy committed Nov 23, 2021
2 parents 8be0a2b + e45de8b commit 977cc23
Show file tree
Hide file tree
Showing 33 changed files with 371 additions and 333 deletions.
32 changes: 17 additions & 15 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"strconv"
"strings"

gsrpc "github.com/Platdot-Network/go-substrate-rpc-client/v3"
gsClient "github.com/Platdot-Network/go-substrate-rpc-client/v3/client"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/rpc"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/scale"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
log2 "github.com/ethereum/go-ethereum/log"
"github.com/rjman-ljm/go-substrate-crypto/ss58"
"golang.org/x/crypto/blake2b"

"github.com/Platdot-Network/substrate-go/expand"
"github.com/Platdot-Network/substrate-go/expand/base"
"github.com/Platdot-Network/substrate-go/expand/chainx/xevents"
"github.com/Platdot-Network/substrate-go/models"
"github.com/Platdot-Network/substrate-go/utils"
gsrc "github.com/centrifuge/go-substrate-rpc-client/v3"
gsClient "github.com/centrifuge/go-substrate-rpc-client/v3/client"
"github.com/centrifuge/go-substrate-rpc-client/v3/rpc"
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
log2 "github.com/ethereum/go-ethereum/log"
"golang.org/x/crypto/blake2b"
"log"
"strconv"
"strings"
)

type Client struct {
Api *gsrc.SubstrateAPI
Api *gsrpc.SubstrateAPI
Meta *types.Metadata
Prefix []byte //币种的前缀
Name string //链名字
Expand All @@ -41,7 +43,7 @@ func New(url string) (*Client, error) {
var err error

// 初始化rpc客户端
c.Api, err = gsrc.NewSubstrateAPI(url)
c.Api, err = gsrpc.NewSubstrateAPI(url)
//Api, err := gsrpc.NewSubstrateAPI(config.Default().RPCURL)
if err != nil {
return nil, err
Expand All @@ -55,7 +57,7 @@ func New(url string) (*Client, error) {
return c, nil
}

func (c *Client) reConnectWs() (*gsrc.SubstrateAPI, error) {
func (c *Client) reConnectWs() (*gsrpc.SubstrateAPI, error) {
cl, err := gsClient.Connect(c.Url)
if err != nil {
return nil, err
Expand All @@ -64,7 +66,7 @@ func (c *Client) reConnectWs() (*gsrc.SubstrateAPI, error) {
if err != nil {
return nil, err
}
return &gsrc.SubstrateAPI{
return &gsrpc.SubstrateAPI{
RPC: newRPC,
Client: cl,
}, nil
Expand Down Expand Up @@ -943,7 +945,7 @@ func (c *Client) GetAccountInfo(address string) (*types.AccountInfo, error) {
if err != nil {
return nil, fmt.Errorf("ss58 decode address error: %v\n", err)
}
storage, err = types.CreateStorageKey(c.Meta, "System", "Account", pub, nil)
storage, err = types.CreateStorageKey(c.Meta, "System", "Account", pub)
if err != nil {
return nil, fmt.Errorf("create System.Account storage error: %v\n", err)
}
Expand Down
4 changes: 2 additions & 2 deletions expand/base/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/hex"
"fmt"

"github.com/Platdot-Network/go-substrate-rpc-client/v3/scale"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/substrate-go/expand/extra"
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

/// Polkadot MultiSignExtrinsic Type
Expand Down
4 changes: 2 additions & 2 deletions expand/bifrost/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package bifrost

import (
"fmt"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/scale"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/substrate-go/expand/base"
"github.com/Platdot-Network/substrate-go/expand/bridge"
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

type BifrostEventRecords struct {
Expand Down
3 changes: 1 addition & 2 deletions expand/bridge/bridge_event.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bridge

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
events "github.com/hacpy/chainbridge-substrate-events"
)

Expand Down Expand Up @@ -39,4 +39,3 @@ type AssetEvents struct {
Registry_RegistryCreated []EventRegistryRegistryCreated //nolint:stylecheck,golint
Registry_RegistryTmp []EventRegistryTmp //nolint:stylecheck,golint
}

2 changes: 1 addition & 1 deletion expand/bridge/bridge_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bridge

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

type Erc721Token struct {
Expand Down
17 changes: 9 additions & 8 deletions expand/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ package expand
import (
"encoding/hex"
"fmt"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"

"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/*
扩展: 创建一个新的Call方法
*/
func NewCall(callIdx string,args ...interface{})(types.Call,error){
if len(callIdx)!=4 {
return types.Call{},fmt.Errorf("callIdx length is not equal 4,len=%d",len(callIdx))
func NewCall(callIdx string, args ...interface{}) (types.Call, error) {
if len(callIdx) != 4 {
return types.Call{}, fmt.Errorf("callIdx length is not equal 4,len=%d", len(callIdx))
}
m,err:=hex.DecodeString(callIdx[:2])
m, err := hex.DecodeString(callIdx[:2])
if err != nil {
return types.Call{}, err
}
n,err:=hex.DecodeString(callIdx[2:])
n, err := hex.DecodeString(callIdx[2:])
if err != nil {
return types.Call{},err
return types.Call{}, err
}
c:=types.CallIndex{SectionIndex: m[0],MethodIndex: n[0]}
c := types.CallIndex{SectionIndex: m[0], MethodIndex: n[0]}
var a []byte
for _, arg := range args {
e, err := types.EncodeToBytes(arg)
Expand Down
56 changes: 28 additions & 28 deletions expand/chainx/pallets/swap.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
package pallets

import "github.com/centrifuge/go-substrate-rpc-client/v3/types"
import "github.com/Platdot-Network/go-substrate-rpc-client/v3/types"

type AssetId types.U32
type Balance types.U128

/// XAssets Type
type Swap struct {
Swap_PairCreated []EventPairCreated
Swap_LiquidityAdded []EventLiquidityAdded
Swap_LiquidityRemoved []EventLiquidityRemoved
Swap_TokenSwap []EventTokenSwap
Swap_PairCreated []EventPairCreated
Swap_LiquidityAdded []EventLiquidityAdded
Swap_LiquidityRemoved []EventLiquidityRemoved
Swap_TokenSwap []EventTokenSwap
}

/// Create a trading pair. \[creator, asset_id, asset_id\]
type EventPairCreated struct {
Phase types.Phase
Creator types.AccountID
AssetA AssetId
AssetB AssetId
Topics []types.Hash
Phase types.Phase
Creator types.AccountID
AssetA AssetId
AssetB AssetId
Topics []types.Hash
}

/// Add liquidity. \[owner, asset_id, asset_id\]
type EventLiquidityAdded struct {
Phase types.Phase
Owner types.AccountID
AssetA AssetId
AssetB AssetId
Topics []types.Hash
Phase types.Phase
Owner types.AccountID
AssetA AssetId
AssetB AssetId
Topics []types.Hash
}

/// Remove liquidity. \[owner, recipient, asset_id, asset_id, amount\]
type EventLiquidityRemoved struct {
Phase types.Phase
Owner types.AccountID
Recipient types.AccountID
AssetA AssetId
AssetB AssetId
Amount Balance
Topics []types.Hash
Phase types.Phase
Owner types.AccountID
Recipient types.AccountID
AssetA AssetId
AssetB AssetId
Amount Balance
Topics []types.Hash
}

/// Transact in trading \[owner, recipient, swap_path\]
type EventTokenSwap struct {
Phase types.Phase
Owner types.AccountID
Recipient types.AccountID
SwapPath []AssetId
Topics []types.Hash
}
Phase types.Phase
Owner types.AccountID
Recipient types.AccountID
SwapPath []AssetId
Topics []types.Hash
}
2 changes: 1 addition & 1 deletion expand/chainx/types.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package chainx

import (
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/substrate-go/expand/base"
"github.com/Platdot-Network/substrate-go/expand/bridge"
"github.com/Platdot-Network/substrate-go/expand/chainx/pallets"
"github.com/Platdot-Network/substrate-go/expand/extra"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

type ChainXEventRecords struct {
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xbtc_events.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package chainx

import (
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/substrate-go/expand/chainx/xevents"
"github.com/Platdot-Network/substrate-go/expand/chainx/xevents/xgateway"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

type XPallets struct {
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xevents/xassets.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xevents

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/// XAssets Type
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xevents/xgateway/xbitcoin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xgateway

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/// XGatewayBitcoin Type
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xevents/xgateway/xcommon.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xgateway

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/// XGatewayCommon Type
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xevents/xgateway/xrecords.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xgateway

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/// XGatewayRecords Type
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xevents/xmining.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xevents

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

///XMining Type
Expand Down
2 changes: 1 addition & 1 deletion expand/chainx/xevents/xsystem.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xevents

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/// XSystem Type
Expand Down
4 changes: 2 additions & 2 deletions expand/chainx_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package expand
import (
"fmt"

"github.com/Platdot-Network/go-substrate-rpc-client/v3/scale"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/substrate-go/expand/chainx/xevents"
"github.com/Platdot-Network/substrate-go/utils"
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/huandu/xstrings"
)

Expand Down
3 changes: 1 addition & 2 deletions expand/event_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package expand
import (
"strings"

"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/substrate-go/expand/bifrost"
"github.com/Platdot-Network/substrate-go/expand/chainx"
"github.com/Platdot-Network/substrate-go/expand/extra"
"github.com/Platdot-Network/substrate-go/expand/polkadot"
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

type IEventRecords interface {
Expand Down Expand Up @@ -80,4 +80,3 @@ func DecodeEventRecords(meta *types.Metadata, rawData string, chainName string)

return ier, nil
}

4 changes: 2 additions & 2 deletions expand/extra/crowdloan.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package extra

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/scale"
gsrpcTypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/scale"
gsrpcTypes "github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

/// Crowdloan
Expand Down
16 changes: 8 additions & 8 deletions expand/extra/election.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package extra

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/Platdot-Network/go-substrate-rpc-client/v3/types"
)

type ElectionsPhragmen struct {
Claims_Claimed []EventClaimsClaimed
ElectionsPhragmen_VoterReported []EventElectionsPhragmenVoterReported
ElectionsPhragmen_MemberRenounced []EventElectionsPhragmenMemberRenounced
ElectionsPhragmen_MemberKicked []EventElectionsPhragmenMemberKicked
ElectionsPhragmen_ElectionError []EventElectionsPhragmenElectionError
ElectionsPhragmen_EmptyTerm []EventElectionsPhragmenEmptyTerm
Claims_Claimed []EventClaimsClaimed
ElectionsPhragmen_VoterReported []EventElectionsPhragmenVoterReported
ElectionsPhragmen_MemberRenounced []EventElectionsPhragmenMemberRenounced
ElectionsPhragmen_MemberKicked []EventElectionsPhragmenMemberKicked
ElectionsPhragmen_ElectionError []EventElectionsPhragmenElectionError
ElectionsPhragmen_EmptyTerm []EventElectionsPhragmenEmptyTerm
//ElectionsPhragmen_NewTerm []EventElectionsPhragmenNewTerm 暂不支持解析
Democracy_Blacklisted []EventDemocracyBlacklisted
Democracy_Blacklisted []EventDemocracyBlacklisted
}

type EventDemocracyBlacklisted struct {
Expand Down
Loading

0 comments on commit 977cc23

Please sign in to comment.