Skip to content

Commit

Permalink
Base p2p 0.0.9 (#35)
Browse files Browse the repository at this point in the history
* update p2p-go to v0.0.9 and Optimize the Client interface

* add protocol init

* add Sign

* add GetSubstrateAPI and GetChainState

* add IdleProtocol init

* add GetMetadata and GetKeyEvents
  • Loading branch information
AstaFrode authored Apr 26, 2023
1 parent 06e4760 commit d9341e5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
30 changes: 30 additions & 0 deletions core/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ type Chain interface {

// GetSignatureAcc returns the signature account.
GetSignatureAcc() string

// GetSignatureURI to get the private key of the signing account
GetSignatureURI() string

// GetSubstrateAPI returns Substrate API
GetSubstrateAPI() *gsrpc.SubstrateAPI

// GetChainState returns chain node state
GetChainState() bool

//
GetMetadata() *types.Metadata

//
GetKeyEvents() types.StorageKey
}

type chainClient struct {
Expand Down Expand Up @@ -229,6 +244,10 @@ func (c *chainClient) GetSignatureAcc() string {
return acc
}

func (c *chainClient) GetKeyEvents() types.StorageKey {
return c.keyEvents
}

// ExtractAccountPublickey
func (c *chainClient) ExtractAccountPuk(account string) ([]byte, error) {
if account != "" {
Expand All @@ -237,6 +256,17 @@ func (c *chainClient) ExtractAccountPuk(account string) ([]byte, error) {
return c.keyring.PublicKey, nil
}

func (c *chainClient) GetSignatureURI() string {
return c.keyring.URI
}

func (c *chainClient) GetSubstrateAPI() *gsrpc.SubstrateAPI {
return c.api
}
func (c *chainClient) GetMetadata() *types.Metadata {
return c.metadata
}

func reconnectChainClient(rpcAddr []string) (*gsrpc.SubstrateAPI, error) {
var err error
var api *gsrpc.SubstrateAPI
Expand Down
6 changes: 6 additions & 0 deletions core/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func NewBasicCli(rpc []string, name, phase, workspace, addr string, port int, ti
cli.Protocol.ReadFileProtocol = protocol.NewReadFileProtocol(p2pnode)
cli.Protocol.MusProtocol = protocol.NewMusProtocol(p2pnode)
cli.Protocol.TagProtocol = protocol.NewTagProtocol(p2pnode)
cli.Protocol.IdleProtocol = protocol.NewIdleProtocol(p2pnode)


//
os.MkdirAll(filepath.Join(workspaceActual, rule.FileDir), rule.DirMode)
Expand All @@ -114,3 +116,7 @@ func NewBasicCli(rpc []string, name, phase, workspace, addr string, port int, ti

return cli, nil
}

func (c *Cli) Sign(msg []byte) ([]byte, error) {
return signature.Sign(msg, c.GetSignatureURI())
}
4 changes: 2 additions & 2 deletions examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Example_registerOss() {
if err != nil {
panic(err)
}
txhash, err := cli.Register("oss", "", 0)
txhash, err := cli.RegisterRole("oss", "", 0)
if err != nil {
panic(err)
}
Expand All @@ -53,7 +53,7 @@ func Example_registerMiner() {
if err != nil {
panic(err)
}
txhash, err := cli.Register("bucket", "cXxxx...xxx", 100000)
txhash, err := cli.RegisterRole("bucket", "cXxxx...xxx", 100000)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit d9341e5

Please sign in to comment.