diff --git a/chain/chain.go b/chain/chain.go index 6a9c036..bf9339e 100644 --- a/chain/chain.go +++ b/chain/chain.go @@ -9,6 +9,7 @@ package chain import ( "context" + "errors" "io" "log" "os" @@ -29,7 +30,7 @@ import ( ) type ChainSDK struct { - core.P2P + *core.Node lock *sync.Mutex api *gsrpc.SubstrateAPI chainState *atomic.Bool @@ -50,6 +51,7 @@ var _ sdk.SDK = (*ChainSDK)(nil) func NewChainSDK(name string, rpcs []string, mnemonic string, t time.Duration, workspace string, p2pPort int, bootnodes []string) (*ChainSDK, error) { var ( + ok bool err error chainSDK = &ChainSDK{} ) @@ -109,7 +111,7 @@ func NewChainSDK(name string, rpcs []string, mnemonic string, t time.Duration, w chainSDK.name = name if workspace != "" && p2pPort > 0 { - chainSDK.P2P, err = p2pgo.New( + p2p, err := p2pgo.New( ctx, p2pgo.ListenPort(p2pPort), p2pgo.Workspace(filepath.Join(workspace, chainSDK.GetSignatureAcc(), chainSDK.GetRoleName())), @@ -118,6 +120,10 @@ func NewChainSDK(name string, rpcs []string, mnemonic string, t time.Duration, w if err != nil { return nil, err } + chainSDK.Node, ok = p2p.(*core.Node) + if !ok { + return nil, errors.New("invalid p2p type") + } chainSDK.enabledP2P = true } diff --git a/chain/fileBank.go b/chain/fileBank.go index 606d198..b3ad474 100644 --- a/chain/fileBank.go +++ b/chain/fileBank.go @@ -797,7 +797,13 @@ func (c *ChainSDK) DeleteFile(puk []byte, filehash []string) (string, []pattern. return txhash, hashs, errors.Wrap(err, "[GetStorageRaw]") } err = types.EventRecordsRaw(*h).DecodeEventRecords(c.metadata, &events) - if err != nil || len(events.FileBank_DeleteFile) > 0 { + if err != nil { + if len(events.FileBank_DeleteFile) > 0 { + return txhash, events.FileBank_DeleteFile[0].Filehash, nil + } + return txhash, nil, nil + } + if len(events.FileBank_DeleteFile) > 0 { return txhash, events.FileBank_DeleteFile[0].Filehash, nil } return txhash, hashs, errors.New(pattern.ERR_Failed) @@ -982,7 +988,14 @@ func (c *ChainSDK) SubmitFileReport(roothash []pattern.FileHash) (string, []patt return txhash, nil, errors.Wrap(err, "[GetStorageRaw]") } err = types.EventRecordsRaw(*h).DecodeEventRecords(c.metadata, &events) - if err != nil || len(events.FileBank_TransferReport) > 0 { + if err != nil { + if len(events.FileBank_TransferReport) > 0 { + return txhash, events.FileBank_TransferReport[0].Failed_list, nil + } else { + return txhash, nil, nil + } + } + if len(events.FileBank_TransferReport) > 0 { return txhash, events.FileBank_TransferReport[0].Failed_list, nil } return txhash, nil, errors.New(pattern.ERR_Failed) @@ -1086,9 +1099,15 @@ func (c *ChainSDK) ReplaceIdleFiles(roothash []pattern.FileHash) (string, []patt return txhash, nil, errors.Wrap(err, "[GetStorageRaw]") } err = types.EventRecordsRaw(*h).DecodeEventRecords(c.metadata, &events) - if err != nil || len(events.FileBank_ReplaceFiller) > 0 { + if err != nil { + if len(events.FileBank_ReplaceFiller) > 0 { + return txhash, events.FileBank_ReplaceFiller[0].Filler_list, nil + } return txhash, nil, nil } + if len(events.FileBank_ReplaceFiller) > 0 { + return txhash, events.FileBank_ReplaceFiller[0].Filler_list, nil + } return txhash, nil, errors.New(pattern.ERR_Failed) } case err = <-sub.Err(): diff --git a/go.mod b/go.mod index bda6ddc..f01843d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/CESSProject/cess-go-sdk go 1.19 require ( - github.com/CESSProject/p2p-go v0.0.33 + github.com/CESSProject/p2p-go v0.0.34 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cbergoon/merkletree v0.2.0 github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.13 diff --git a/go.sum b/go.sum index 334d4fb..b4bace0 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/CESSProject/p2p-go v0.0.33 h1:2EXMEa1RAFHWfRTd5O6pyKQMBIbpsedIJvlYAFX/Qp0= -github.com/CESSProject/p2p-go v0.0.33/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw= +github.com/CESSProject/p2p-go v0.0.34 h1:KgWA/kvJq8M4EtmZ1jcP33udx8OJeIbVKcJXIGmi6SE= +github.com/CESSProject/p2p-go v0.0.34/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=