status-go-sdk/sdk.go

71 lines
1.5 KiB
Go
Raw Normal View History

2018-04-30 15:57:11 +00:00
package sdk
2018-05-04 14:12:36 +00:00
// RPCClient is a client to manage all rpc calls
type RPCClient interface {
Call(result interface{}, method string, args ...interface{}) error
2018-05-04 14:12:36 +00:00
}
// SDK is a set of tools to interact with status node
type SDK struct {
RPCClient RPCClient
minimumPoW float64
2018-04-30 15:57:11 +00:00
}
// New creates a default SDK object
func New(c RPCClient) *SDK {
return &SDK{
RPCClient: c,
minimumPoW: 0.001,
2018-04-30 15:57:11 +00:00
}
}
// Login to status with the given credentials
func (c *SDK) Login(addr, pwd string) (a *Account, err error) {
res, err := statusLoginRequest(c, addr, pwd)
if err != nil {
return a, err
2018-04-30 15:57:11 +00:00
}
return &Account{
2018-06-08 15:33:24 +00:00
conn: c,
AddressKeyID: res.AddressKeyID,
}, err
2018-04-30 15:57:11 +00:00
}
// Signup creates a new account with the given credentials
func (c *SDK) Signup(pwd string) (a *Account, err error) {
res, err := statusSignupRequest(c, pwd)
2018-06-08 15:33:24 +00:00
if err != nil {
return a, err
2018-04-30 15:57:11 +00:00
}
return &Account{
conn: c,
2018-05-11 05:55:55 +00:00
Address: res.Address,
PubKey: res.Pubkey,
Mnemonic: res.Mnemonic,
}, err
2018-04-30 15:57:11 +00:00
}
// SignupAndLogin sign up and login on status network
func (c *SDK) SignupAndLogin(password string) (a *Account, err error) {
a, err = c.Signup(password)
if err != nil {
return
2018-04-30 15:57:11 +00:00
}
la, err := c.Login(a.Address, password)
2018-06-08 15:33:24 +00:00
a.AddressKeyID = la.AddressKeyID
return
2018-04-30 15:57:11 +00:00
}
2018-05-30 12:49:47 +00:00
// Request json request.
2018-05-11 05:55:55 +00:00
type Request struct {
Method string `json:"method"`
Params interface{} `json:"params"`
}
// NewMessageFilterResponse NewMessageFilter json response
type NewMessageFilterResponse struct {
Result string `json:"result"`
}