You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.3 KiB

package rpc
import (
"github.com/ybbus/jsonrpc"
)
type Client struct {
rpcClient jsonrpc.RPCClient
}
func (c *Client) CreateWallet(name, language string) error {
type params struct {
Filename string `json:"filename"`
Password string `json:"password"`
Language string `json:"language"`
}
resp, err := c.rpcClient.Call("create_wallet", params{
Filename: name,
Language: language,
})
if err != nil {
return err
}
if err := resp.Error; err != nil {
return err
}
return nil
}
func (c *Client) OpenWallet(name string) error {
type params struct {
Filename string `json:"filename"`
Password string `json:"password"`
}
resp, err := c.rpcClient.Call("open_wallet", params{
Filename: name,
})
if err != nil {
return err
}
if err := resp.Error; err != nil {
return err
}
return nil
}
// TODO: close wallet!
func (c *Client) IsMultisig() (bool, error) {
resp, err := c.rpcClient.Call("is_multisig")
if err != nil {
return false, err
}
if err := resp.Error; err != nil {
return false, err
}
isMultisig := resp.Result.(map[string]interface{})["multisig"].(bool)
isReady := resp.Result.(map[string]interface{})["ready"].(bool)
return isMultisig && isReady, nil
}
func (c *Client) PrepareMultisig(out interface{}) error {
return c.rpcClient.CallFor(&out, "prepare_multisig")
}
func (c *Client) MakeMultisig(threshold uint, multiSigInfo []string, out interface{}) error {
type params struct {
MultisigInfo []string `json:"multisig_info"`
Threshold uint `json:"threshold"`
Password string `json:"password"`
}
return c.rpcClient.CallFor(&out, "make_multisig", params{
MultisigInfo: multiSigInfo,
Threshold: threshold,
})
}
func (c *Client) FinalizeMultisig(multiSigInfo []string, out interface{}) error {
type params struct {
MultisigInfo []string `json:"multisig_info"`
Password string `json:"password"`
}
return c.rpcClient.CallFor(&out, "finalize_multisig", params{
MultisigInfo: multiSigInfo,
})
}
func (c *Client) Transfer(address string, amount uint, out interface{}) error {
type params struct {
Destinations []interface{} `json:"destinations"`
}
return c.rpcClient.CallFor(&out, "transfer", params{
Destinations: []interface{}{amount, address},
})
}
func NewClient(uri string) *Client {
return &Client{
rpcClient: jsonrpc.NewClient(uri),
}
}