Move wallet types into types.go, and standardize wallet stuff to more closely match chat stuff
This commit is contained in:
67
types.go
67
types.go
@ -198,6 +198,73 @@ type Chat struct {
|
|||||||
Channel Channel
|
Channel Channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WalletAPI holds data for sending to API
|
||||||
|
type WalletAPI struct {
|
||||||
|
Method string `json:"method"`
|
||||||
|
Params wParams `json:"params"`
|
||||||
|
Result wResult `json:"result"`
|
||||||
|
}
|
||||||
|
type wOptions struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Txid string `json:"txid"`
|
||||||
|
}
|
||||||
|
type wParams struct {
|
||||||
|
Options wOptions `json:"options"`
|
||||||
|
}
|
||||||
|
type asset struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Issuer string `json:"issuer"`
|
||||||
|
VerifiedDomain string `json:"verifiedDomain"`
|
||||||
|
IssuerName string `json:"issuerName"`
|
||||||
|
Desc string `json:"desc"`
|
||||||
|
InfoURL string `json:"infoUrl"`
|
||||||
|
}
|
||||||
|
type sourceAsset struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Issuer string `json:"issuer"`
|
||||||
|
VerifiedDomain string `json:"verifiedDomain"`
|
||||||
|
IssuerName string `json:"issuerName"`
|
||||||
|
Desc string `json:"desc"`
|
||||||
|
InfoURL string `json:"infoUrl"`
|
||||||
|
}
|
||||||
|
type balance struct {
|
||||||
|
Asset asset `json:"asset"`
|
||||||
|
Amount string `json:"amount"`
|
||||||
|
Limit string `json:"limit"`
|
||||||
|
}
|
||||||
|
type exchangeRate struct {
|
||||||
|
Currency string `json:"currency"`
|
||||||
|
Rate string `json:"rate"`
|
||||||
|
}
|
||||||
|
type wResult struct {
|
||||||
|
AccountID string `json:"accountID"`
|
||||||
|
IsPrimary bool `json:"isPrimary"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Balance []balance `json:"balance"`
|
||||||
|
ExchangeRate exchangeRate `json:"exchangeRate"`
|
||||||
|
AccountMode int `json:"accountMode"`
|
||||||
|
TxID string `json:"txID"`
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
StatusDetail string `json:"statusDetail"`
|
||||||
|
Amount string `json:"amount"`
|
||||||
|
Asset asset `json:"asset"`
|
||||||
|
DisplayAmount string `json:"displayAmount"`
|
||||||
|
DisplayCurrency string `json:"displayCurrency"`
|
||||||
|
SourceAmountMax string `json:"sourceAmountMax"`
|
||||||
|
SourceAmountActual string `json:"sourceAmountActual"`
|
||||||
|
SourceAsset sourceAsset `json:"sourceAsset"`
|
||||||
|
FromStellar string `json:"fromStellar"`
|
||||||
|
ToStellar string `json:"toStellar"`
|
||||||
|
FromUsername string `json:"fromUsername"`
|
||||||
|
ToUsername string `json:"toUsername"`
|
||||||
|
Note string `json:"note"`
|
||||||
|
NoteErr string `json:"noteErr"`
|
||||||
|
Unread bool `json:"unread"`
|
||||||
|
}
|
||||||
|
|
||||||
type chat interface {
|
type chat interface {
|
||||||
Send(message ...string) (ChatAPI, error)
|
Send(message ...string) (ChatAPI, error)
|
||||||
Edit(messageID int, message ...string) (ChatAPI, error)
|
Edit(messageID int, message ...string) (ChatAPI, error)
|
||||||
|
|||||||
83
wallet.go
83
wallet.go
@ -5,96 +5,25 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
//walletOut holds data for sending to API
|
|
||||||
type walletOut struct {
|
|
||||||
Method string `json:"method"`
|
|
||||||
Params walletOutParams `json:"params"`
|
|
||||||
}
|
|
||||||
type walletOutOptions struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Txid string `json:"txid"`
|
|
||||||
}
|
|
||||||
type walletOutParams struct {
|
|
||||||
Options walletOutOptions `json:"options"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// walletOutResult holds data data received after sending to API
|
|
||||||
type walletOutResult struct {
|
|
||||||
Result WalletResult `json:"result"`
|
|
||||||
}
|
|
||||||
type asset struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Code string `json:"code"`
|
|
||||||
Issuer string `json:"issuer"`
|
|
||||||
VerifiedDomain string `json:"verifiedDomain"`
|
|
||||||
IssuerName string `json:"issuerName"`
|
|
||||||
Desc string `json:"desc"`
|
|
||||||
InfoURL string `json:"infoUrl"`
|
|
||||||
}
|
|
||||||
type sourceAsset struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Code string `json:"code"`
|
|
||||||
Issuer string `json:"issuer"`
|
|
||||||
VerifiedDomain string `json:"verifiedDomain"`
|
|
||||||
IssuerName string `json:"issuerName"`
|
|
||||||
Desc string `json:"desc"`
|
|
||||||
InfoURL string `json:"infoUrl"`
|
|
||||||
}
|
|
||||||
type balance struct {
|
|
||||||
Asset asset `json:"asset"`
|
|
||||||
Amount string `json:"amount"`
|
|
||||||
Limit string `json:"limit"`
|
|
||||||
}
|
|
||||||
type exchangeRate struct {
|
|
||||||
Currency string `json:"currency"`
|
|
||||||
Rate string `json:"rate"`
|
|
||||||
}
|
|
||||||
type WalletResult struct {
|
|
||||||
AccountID string `json:"accountID"`
|
|
||||||
IsPrimary bool `json:"isPrimary"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Balance []balance `json:"balance"`
|
|
||||||
ExchangeRate exchangeRate `json:"exchangeRate"`
|
|
||||||
AccountMode int `json:"accountMode"`
|
|
||||||
TxID string `json:"txID"`
|
|
||||||
Time int64 `json:"time"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
StatusDetail string `json:"statusDetail"`
|
|
||||||
Amount string `json:"amount"`
|
|
||||||
Asset asset `json:"asset"`
|
|
||||||
DisplayAmount string `json:"displayAmount"`
|
|
||||||
DisplayCurrency string `json:"displayCurrency"`
|
|
||||||
SourceAmountMax string `json:"sourceAmountMax"`
|
|
||||||
SourceAmountActual string `json:"sourceAmountActual"`
|
|
||||||
SourceAsset sourceAsset `json:"sourceAsset"`
|
|
||||||
FromStellar string `json:"fromStellar"`
|
|
||||||
ToStellar string `json:"toStellar"`
|
|
||||||
FromUsername string `json:"fromUsername"`
|
|
||||||
ToUsername string `json:"toUsername"`
|
|
||||||
Note string `json:"note"`
|
|
||||||
NoteErr string `json:"noteErr"`
|
|
||||||
Unread bool `json:"unread"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// walletAPIOut sends JSON requests to the wallet API and returns its response.
|
// walletAPIOut sends JSON requests to the wallet API and returns its response.
|
||||||
func walletAPIOut(keybasePath string, w walletOut) (walletOutResult, error) {
|
func walletAPIOut(keybasePath string, w WalletAPI) (WalletAPI, error) {
|
||||||
jsonBytes, _ := json.Marshal(w)
|
jsonBytes, _ := json.Marshal(w)
|
||||||
|
|
||||||
cmd := exec.Command(keybasePath, "wallet", "api", "-m", string(jsonBytes))
|
cmd := exec.Command(keybasePath, "wallet", "api", "-m", string(jsonBytes))
|
||||||
cmdOut, err := cmd.Output()
|
cmdOut, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return walletOutResult{}, err
|
return WalletAPI{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var r walletOutResult
|
var r WalletAPI
|
||||||
json.Unmarshal(cmdOut, &r)
|
json.Unmarshal(cmdOut, &r)
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TxDetail returns details of a stellar transaction
|
// TxDetail returns details of a stellar transaction
|
||||||
func (k *Keybase) TxDetail(txid string) (WalletResult, error) {
|
func (k *Keybase) TxDetail(txid string) (wResult, error) {
|
||||||
m := walletOut{}
|
m := WalletAPI{}
|
||||||
m.Method = "details"
|
m.Method = "details"
|
||||||
m.Params.Options.Txid = txid
|
m.Params.Options.Txid = txid
|
||||||
|
|
||||||
@ -104,7 +33,7 @@ func (k *Keybase) TxDetail(txid string) (WalletResult, error) {
|
|||||||
|
|
||||||
// StellarAddress returns the primary stellar address of a given user
|
// StellarAddress returns the primary stellar address of a given user
|
||||||
func (k *Keybase) StellarAddress(user string) (string, error) {
|
func (k *Keybase) StellarAddress(user string) (string, error) {
|
||||||
m := walletOut{}
|
m := WalletAPI{}
|
||||||
m.Method = "lookup"
|
m.Method = "lookup"
|
||||||
m.Params.Options.Name = user
|
m.Params.Options.Name = user
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user