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 {
|
2018-05-16 18:07:42 +00:00
|
|
|
Call(result interface{}, method string, args ...interface{}) error
|
2018-05-04 14:12:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:07:36 +00:00
|
|
|
// SDK is a set of tools to interact with status node
|
|
|
|
type SDK struct {
|
|
|
|
RPCClient RPCClient
|
2018-05-01 07:46:34 +00:00
|
|
|
minimumPoW float64
|
2018-04-30 15:57:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:07:36 +00:00
|
|
|
// New creates a default SDK object
|
2018-05-04 13:49:23 +00:00
|
|
|
func New(c RPCClient) *SDK {
|
2018-04-30 17:07:36 +00:00
|
|
|
return &SDK{
|
2018-05-04 13:49:23 +00:00
|
|
|
RPCClient: c,
|
2018-05-01 07:46:34 +00:00
|
|
|
minimumPoW: 0.001,
|
2018-04-30 15:57:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 17:07:36 +00:00
|
|
|
// Login to status with the given credentials
|
2018-05-07 10:03:45 +00:00
|
|
|
func (c *SDK) Login(addr, pwd string) (a *Account, err error) {
|
2018-05-03 13:24:38 +00:00
|
|
|
res, err := statusLoginRequest(c, addr, pwd)
|
|
|
|
if err != nil {
|
2018-05-07 10:03:45 +00:00
|
|
|
return a, err
|
2018-04-30 15:57:11 +00:00
|
|
|
}
|
2018-05-07 10:03:45 +00:00
|
|
|
return &Account{
|
2018-06-08 15:33:24 +00:00
|
|
|
conn: c,
|
|
|
|
AddressKeyID: res.AddressKeyID,
|
2018-05-07 10:03:45 +00:00
|
|
|
}, err
|
2018-04-30 15:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Signup creates a new account with the given credentials
|
2018-05-07 10:03:45 +00:00
|
|
|
func (c *SDK) Signup(pwd string) (a *Account, err error) {
|
2018-05-03 13:24:38 +00:00
|
|
|
res, err := statusSignupRequest(c, pwd)
|
2018-06-08 15:33:24 +00:00
|
|
|
|
2018-05-03 13:24:38 +00:00
|
|
|
if err != nil {
|
2018-05-07 10:03:45 +00:00
|
|
|
return a, err
|
2018-04-30 15:57:11 +00:00
|
|
|
}
|
2018-05-07 10:03:45 +00:00
|
|
|
return &Account{
|
2018-05-07 13:22:33 +00:00
|
|
|
conn: c,
|
2018-05-11 05:55:55 +00:00
|
|
|
Address: res.Address,
|
|
|
|
PubKey: res.Pubkey,
|
|
|
|
Mnemonic: res.Mnemonic,
|
2018-05-07 10:03:45 +00:00
|
|
|
}, err
|
2018-04-30 15:57:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-01 07:46:34 +00:00
|
|
|
// SignupAndLogin sign up and login on status network
|
2018-05-07 10:03:45 +00:00
|
|
|
func (c *SDK) SignupAndLogin(password string) (a *Account, err error) {
|
|
|
|
a, err = c.Signup(password)
|
2018-05-01 07:46:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
2018-04-30 15:57:11 +00:00
|
|
|
}
|
2018-05-07 10:03:45 +00:00
|
|
|
la, err := c.Login(a.Address, password)
|
2018-06-08 15:33:24 +00:00
|
|
|
a.AddressKeyID = la.AddressKeyID
|
2018-05-01 07:46:34 +00:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2018-05-01 07:46:34 +00:00
|
|
|
// NewMessageFilterResponse NewMessageFilter json response
|
|
|
|
type NewMessageFilterResponse struct {
|
|
|
|
Result string `json:"result"`
|
|
|
|
}
|