walletrpc

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPaymentID256

func NewPaymentID256() (string, error)

NewPaymentID256 generates a 256 bit payment ID (hex encoded).

func NewPaymentID64

func NewPaymentID64() (string, error)

NewPaymentID64 generates a 64 bit payment ID (hex encoded). With 64 bit IDs, there is a non-negligible chance of a collision if they are randomly generated. It is up to recipients generating them to sanity check for uniqueness.

1 million IDs at 64-bit (simplified): 1,000,000^2 / (2^64 * 2) = ~1/36,893,488 so there is a 50% chance a collision happens around 5.06 billion IDs generated.

func XMRToDecimal

func XMRToDecimal(xmr uint64) string

XMRToDecimal converts a raw atomic XMR balance to a more human readable format.

func XMRToFloat64

func XMRToFloat64(xmr uint64) float64

XMRToFloat64 converts raw atomic XMR to a float64

Types

type AddressBookEntry

type AddressBookEntry struct {
	Address     string `json:"address"`
	Description string `json:"description,omitempty"`
	Index       uint64 `json:"index,omitempty"`
	PaymentID   string `json:"payment_id,omitempty"`
}

AddressBookEntry Address

type Block

type Block struct {
	Blob        string      `json:"blob"`
	BlockHeader BlockHeader `json:"block_header"`
	Txs         []string    `json:"tx_hashes"`
	Status      string      `json:"status"`
}

type BlockHeader

type BlockHeader struct {
	Depth        uint64 `json:"depth"`
	Difficulty   uint   `json:"difficulty"`
	Hash         string `json:"hash"`
	Height       uint   `json:"height"`
	MajorVersion uint   `json:"major_version"`
	MinorVersion uint   `json:"minor_version"`
	Nonce        uint   `json:"nonce"`
	OrphanStatus bool   `json:"orphan_status"`
	PrevHash     string `json:"prev_hash"`
	Reward       uint   `json:"reward "`
	Timestamp    uint   `json:"timestamp"`
}

type BlockHeaderResponse

type BlockHeaderResponse struct {
	BlockHeader BlockHeader `json:"block_header"`
	Status      string      `json:"status"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *Client

func (*Client) AddAddressBook

func (c *Client) AddAddressBook(entry AddressBookEntry) (index uint64, err error)

func (*Client) CreateWallet

func (c *Client) CreateWallet(filename, password, language string) error

func (*Client) DeleteAddressBook

func (c *Client) DeleteAddressBook(index uint64) error

func (*Client) ExportKeyImages

func (c *Client) ExportKeyImages() ([]SignedKeyImage, error)

func (*Client) GetAddress

func (c *Client) GetAddress() (string, error)

func (*Client) GetAddressBook

func (c *Client) GetAddressBook(indexes []uint64) ([]AddressBookEntry, error)

func (*Client) GetBalance

func (c *Client) GetBalance() (uint64, uint64, error)

func (*Client) GetBlockByHash

func (c *Client) GetBlockByHash(hash string) (res Block, err error)

func (*Client) GetBlockByHeight

func (c *Client) GetBlockByHeight(height uint) (res Block, err error)

func (*Client) GetBulkPayments

func (c *Client) GetBulkPayments(payments []string, minHeight uint) ([]Payment, error)

func (*Client) GetHeight

func (c *Client) GetHeight() (uint64, error)

func (*Client) GetLanguages

func (c *Client) GetLanguages() ([]string, error)

func (*Client) GetLastBlockHeader

func (c *Client) GetLastBlockHeader() (res BlockHeaderResponse, err error)

func (*Client) GetPayments

func (c *Client) GetPayments(id string) ([]Payment, error)

func (*Client) GetTransferByTxID

func (c *Client) GetTransferByTxID(tx string) (transfer Transfer, err error)

func (*Client) GetTransfers

func (c *Client) GetTransfers(req GetTransfersRequest) (resp GetTransfersResponse, err error)

func (*Client) GetTxNotes

func (c *Client) GetTxNotes(txids []string) (notes []string, err error)

func (*Client) ImportKeyImages

func (c *Client) ImportKeyImages(images []SignedKeyImage) (resp ImportKeyImageResponse, err error)

func (*Client) IncomingTransfers

func (c *Client) IncomingTransfers(transfer GetTransferType) ([]IncTransfer, error)

func (*Client) MakeIntegratedAddress

func (c *Client) MakeIntegratedAddress(paymentid string) (integratedaddr string, err error)

func (*Client) MakeURI

func (c *Client) MakeURI(req URIDef) (uri string, err error)

func (*Client) OpenWallet

func (c *Client) OpenWallet(filename, password string) error

func (*Client) ParseURI

func (c *Client) ParseURI(uri string) (parsed *URIDef, err error)

func (*Client) QueryKey

func (c *Client) QueryKey(keytype QueryKeyType) (key string, err error)

func (*Client) RescanBlockchain

func (c *Client) RescanBlockchain() error

func (*Client) RescanSpent

func (c *Client) RescanSpent() error

func (*Client) SetTxNotes

func (c *Client) SetTxNotes(txids, notes []string) error

func (*Client) Sign

func (c *Client) Sign(data string) (signature string, err error)

func (*Client) SplitIntegratedAddress

func (c *Client) SplitIntegratedAddress(integratedaddr string) (paymentid, address string, err error)

func (*Client) StartMining

func (c *Client) StartMining(threads uint, background, ignorebattery bool) error

func (*Client) StopMining

func (c *Client) StopMining() error

func (*Client) StopWallet

func (c *Client) StopWallet() error

func (*Client) Store

func (c *Client) Store() error

func (*Client) SweepAll

func (c *Client) SweepAll(req SweepAllRequest) (resp SweepAllResponse, err error)

func (*Client) SweepDust

func (c *Client) SweepDust() ([]string, error)

func (*Client) Transfer

func (c *Client) Transfer(req TransferRequest) (resp TransferResponse, err error)

func (*Client) TransferSplit

func (c *Client) TransferSplit(req TransferRequest) (resp TransferSplitResponse, err error)

func (*Client) Verify

func (c *Client) Verify(data, address, signature string) (good bool, err error)

type Config

type Config struct {
	Address       string
	CustomHeaders map[string]string
	Transport     http.RoundTripper
}

Config holds the configuration of a monero rpc client.

type Destination

type Destination struct {
	// Amount - unsigned int; Amount to send to each destination, in atomic units.
	Amount uint64 `json:"amount"`
	// Address - string; Destination public address.
	Address string `json:"address"`
}

Destination to receive XMR

type ErrorCode

type ErrorCode int

ErrorCode is a monero-wallet-rpc error code. Copied from https://github.com/monero-project/monero/blob/release-v0.11.0.0/src/wallet/wallet_rpc_server_error_codes.h

const (
	// ErrUnknown - E_UNKNOWN_ERROR
	ErrUnknown ErrorCode = -1
	// ErrWrongAddress - E_WRONG_ADDRESS
	ErrWrongAddress ErrorCode = -2
	// ErrDaemonIsBusy - E_DAEMON_IS_BUSY
	ErrDaemonIsBusy ErrorCode = -3
	// ErrGenericTransferError - E_GENERIC_TRANSFER_ERROR
	ErrGenericTransferError ErrorCode = -4
	// ErrWrongPaymentID - E_WRONG_PAYMENT_ID
	ErrWrongPaymentID ErrorCode = -5
	// ErrTransferType - E_TRANSFER_TYPE
	ErrTransferType ErrorCode = -6
	// ErrDenied - E_DENIED
	ErrDenied ErrorCode = -7
	// ErrWrongTxID - E_WRONG_TXID
	ErrWrongTxID ErrorCode = -8
	// ErrWrongSignature - E_WRONG_SIGNATURE
	ErrWrongSignature ErrorCode = -9
	// ErrWrongKeyImage - E_WRONG_KEY_IMAGE
	ErrWrongKeyImage ErrorCode = -10
	// ErrWrongURI - E_WRONG_URI
	ErrWrongURI ErrorCode = -11
	// ErrWrongIndex - E_WRONG_INDEX
	ErrWrongIndex ErrorCode = -12
	// ErrNotOpen - E_NOT_OPEN
	ErrNotOpen ErrorCode = -13
)

type GetTransferType

type GetTransferType string

GetTransferType is a string that contains the possible types: "all": all the transfers; "available": only transfers which are not yet spent; "unavailable": only transfers which are already spent.

const (
	// TransferAll - all the transfers
	TransferAll GetTransferType = "all"
	// TransferAvailable - only transfers which are not yet spent
	TransferAvailable GetTransferType = "available"
	// TransferUnavailable - only transfers which are already spent
	TransferUnavailable GetTransferType = "unavailable"
)

type GetTransfersRequest

type GetTransfersRequest struct {
	In             bool   `json:"in"`
	Out            bool   `json:"out"`
	Pending        bool   `json:"pending"`
	Failed         bool   `json:"failed"`
	Pool           bool   `json:"pool"`
	FilterByHeight bool   `json:"filter_by_height"`
	MinHeight      uint64 `json:"min_height"`
	MaxHeight      uint64 `json:"max_height"`
}

GetTransfersRequest = GetTransfers body

type GetTransfersResponse

type GetTransfersResponse struct {
	In      []Transfer `json:"in"`
	Out     []Transfer `json:"out"`
	Pending []Transfer `json:"pending"`
	Failed  []Transfer `json:"failed"`
	Pool    []Transfer `json:"pool"`
}

GetTransfersResponse = GetTransfers output

type H

type H map[string]interface{}

H is a helper map shortcut.

type ImportKeyImageResponse

type ImportKeyImageResponse struct {
	Height  uint64 `json:"height"`
	Spent   uint64 `json:"spent"`
	Unspent uint64 `json:"unspent"`
}

ImportKeyImageResponse is the result of ImportKeyImages()

type IncTransfer

type IncTransfer struct {
	Amount uint64 `json:"amount"`
	Spent  bool   `json:"spent"`
	// Mostly internal use, can be ignored by most users.
	GlobalIndex uint64 `json:"global_index"`
	// Several incoming transfers may share the same hash
	// if they were in the same transaction.
	TxHash string `json:"tx_hash"`
	TxSize uint64 `json:"tx_size"`
}

IncTransfer is returned by IncomingTransfers

type Payment

type Payment struct {
	PaymentID   string `json:"payment_id"`
	TxHash      string `json:"tx_hash"`
	Amount      uint64 `json:"amount"`
	BlockHeight uint64 `json:"block_height"`
	UnlockTime  uint64 `json:"unlock_time"`
}

Payment ...

type Priority

type Priority uint

Priority represents a transaction priority

const (
	PriorityDefault     Priority = 0
	PriorityUnimportant Priority = 1
	PriorityNormal      Priority = 2
	PriorityElevated    Priority = 3
)

Accepted Values are: 0-3 for: default, unimportant, normal, elevated, priority.

type QueryKeyType

type QueryKeyType string

QueryKeyType is the parameter to send with client.QueryKey()

const (
	// QueryKeyMnemonic is the mnemonic seed
	QueryKeyMnemonic QueryKeyType = "mnemonic"
	// QueryKeyView is the private view key
	QueryKeyView QueryKeyType = "view_key"
	// QueryKeySpend is the private spend key
	QueryKeySpend QueryKeyType = "spend_key"
)

type SignedKeyImage

type SignedKeyImage struct {
	KeyImage  string `json:"key_image"`
	Signature string `json:"signature"`
}

SignedKeyImage - The key image is an alternate public key computed on a second base point, Hp(P), instead of G. It is required in traceable ring signature construction to ensure multiple signatures with the same real key are linked.

type SweepAllRequest

type SweepAllRequest struct {
	// address - string; Destination public address.
	Address string `json:"address"`
	// payment_id - string; (Optional) Random 32-byte/64-character hex string to identify a transaction.
	PaymentID string `json:"payment_id,omitempty"`
	// priority - unsigned int; (Optional)
	Priority Priority `json:"priority,omitempty"`
	// mixin - unsigned int; Number of outpouts from the blockchain to mix with (0 means no mixing).
	Mixin uint64 `json:"mixin"`
	// unlock_time - unsigned int; Number of blocks before the monero can be spent (0 to not add a lock).
	UnlockTime uint64 `json:"unlock_time"`
	// below_amount - unsigned int; (Optional)
	BelowAmount uint64 `json:"below_amount"`
	// get_tx_keys - boolean; (Optional) Return the transaction keys after sending.
	GetTxKeys bool `json:"get_tx_keys,omitempty"`
	// do_not_relay - boolean; (Optional)
	DoNotRelay bool `json:"do_not_relay,omitempty"`
	// get_tx_hex - boolean; (Optional) return the transactions as hex encoded string.
	GetTxHex bool `json:"get_tx_hex,omitempty"`
}

SweepAllRequest is the struct to send all unlocked balance to an address.

type SweepAllResponse

type SweepAllResponse struct {
	// tx_hash_list - array of: string. The tx hashes of every transaction.
	TxHashList []string `json:"tx_hash_list"`
	// tx_blob_list - array of: string. The tx as hex string for every transaction.
	TxBlobList []string `json:"tx_blob_list"`
	// tx_key_list - array of: string. The transaction keys for every transaction.
	TxKeyList []string `json:"tx_key_list"`
}

SweepAllResponse is a tipical response of a SweepAllRequest

type Transfer

type Transfer struct {
	TxID          string        `json:"txid"`
	PaymentID     string        `json:"payment_id"`
	Height        uint64        `json:"height"`
	Timestamp     uint64        `json:"timestamp"`
	Amount        uint64        `json:"amount"`
	Fee           uint64        `json:"fee"`
	Note          string        `json:"note"`
	Destinations  []Destination `json:"destinations,omitempty"`
	Type          string        `json:"type"`
	Address       string        `json:"address"`
	Confirmations uint64        `json:"confirmations"`
}

Transfer is the transfer data of

type TransferRequest

type TransferRequest struct {
	// unsigned int; (Optional) Transfer from this account index
	AccountIndex uint64 `json:"account_index"`
	// unsigned int; Number of outputs to mix in the transaction (this output + N decoys from the blockchain).
	RingSize uint64 `json:"ring_size"`
	// Destinations - array of destinations to receive XMR:
	Destinations []Destination `json:"destinations"`
	// payment_id - string; (Optional) Random 32-byte/64-character hex string to identify a transaction.
	PaymentID string `json:"payment_id,omitempty"`
	// Fee - unsigned int; Ignored, will be automatically calculated.
	Fee uint64 `json:"fee,omitempty"`
	// Mixin - unsigned int; Number of outpouts from the blockchain to mix with (0 means no mixing).
	Mixin uint64 `json:"mixin"`
	// unlock_time - unsigned int; Number of blocks before the monero can be spent (0 to not add a lock).
	UnlockTime uint64 `json:"unlock_time"`
	// priority - unsigned int; Set a priority for the transaction.
	// Accepted Values are: 0-3 for: default, unimportant, normal, elevated, priority.
	Priority Priority `json:"priority"`
	// get_tx_key - boolean; (Optional) Return the transaction key after sending.
	GetTxKey bool `json:"get_tx_key"`
	// do_not_relay - boolean; (Optional) If true, the newly created transaction will not be relayed to the monero network. (Defaults to false)
	DoNotRelay bool `json:"do_not_relay,omitempty"`
	// get_tx_hex - boolean; Return the transaction as hex string after sending
	GetTxHex bool `json:"get_tx_hex,omitempty"`
}

TransferRequest is the request body of the Transfer client rpc call.

type TransferResponse

type TransferResponse struct {
	// fee - Integer value of the fee charged for the txn.
	Fee uint64 `json:"fee"`
	// tx_hash - String for the publically searchable transaction hash
	TxHash string `json:"tx_hash"`
	// tx_key - String for the transaction key if get_tx_key is true, otherwise, blank string.
	TxKey string `json:"tx_key,omitempty"`
	// tx_blob - Transaction as hex string if get_tx_hex is true
	TxBlob string `json:"tx_blob,omitempty"`
}

TransferResponse is the successful output of a Client.Transfer()

type TransferSplitResponse

type TransferSplitResponse struct {
	// fee_list - array of: integer. The amount of fees paid for every transaction.
	FeeList []uint64 `json:"fee_list"`
	// tx_hash_list - array of: string. The tx hashes of every transaction.
	TxHashList []string `json:"tx_hash_list"`
	// tx_blob_list - array of: string. The tx as hex string for every transaction.
	TxBlobList []string `json:"tx_blob_list"`
	// amount_list - array of: integer. The amount transferred for every transaction..
	AmountList []uint64 `json:"amount_list"`
	// tx_key_list - array of: string. The transaction keys for every transaction.
	TxKeyList []string `json:"tx_key_list"`
}

TransferSplitResponse is the successful output of a Client.TransferSplit()

type URIDef

type URIDef struct {
	// address - wallet address string
	Address string `json:"address"`
	// amount (optional) - the integer amount to receive, in atomic units
	Amount uint64 `json:"amount,omitempty"`
	// payment_id (optional) - 16 or 64 character hexadecimal payment id string
	PaymentID string `json:"payment_id,omitempty"`
	// recipient_name (optional) - string name of the payment recipient
	RecipientName string `json:"recipient_name,omitempty"`
	// tx_description (optional) - string describing the reason for the tx
	TxDescription string `json:"tx_description,omitempty"`
}

URIDef is the skeleton of the MakeURI()

type WalletError

type WalletError struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
}

WalletError is the error structured returned by the monero-wallet-rpc

func GetWalletError

func GetWalletError(err error) (isWalletError bool, werr *WalletError)

GetWalletError checks if an erro interface is a wallet-rpc error.

func (*WalletError) Error

func (we *WalletError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL