monero

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package monero provides client libraries for working with wallet files and interacting with a monero node. Management of monero-wallet-rpc daemon instances is fully encapsulated by these libraries.

Index

Constants

View Source
const (

	// MinSpendConfirmations is the number of confirmations required on transaction
	// outputs before they can be spent again.
	MinSpendConfirmations = 10

	// SweepToSelfConfirmations is the number of confirmations that we wait for when
	// sweeping funds from an A+B wallet to our primary wallet.
	SweepToSelfConfirmations = 2
)
View Source
const (
	// MonerodRegtestEndpoint is the RPC endpoint used by monerod in the dev environment's regtest mode.
	MonerodRegtestEndpoint = "http://127.0.0.1:18081/json_rpc"
)

Variables

This section is empty.

Functions

func BackgroundMineBlocks

func BackgroundMineBlocks(ctx context.Context, blockRewardAddress *mcrypto.Address)

BackgroundMineBlocks starts a background go routine to mine blocks in a monerod instance that is in regtest mode. If there is an existing go routine that is already mining from a previous call, no new go routine is created.

func GetBalance

func GetBalance(t *testing.T, wc WalletClient) *wallet.GetBalanceResponse

GetBalance is a convenience method for tests that assumes you want the primary address and that errors should fail the test.

func GetWalletRPCDirectory

func GetWalletRPCDirectory(t *testing.T) string

GetWalletRPCDirectory returns the directory path of monero-wallet-rpc.

func MineMinXMRBalance

func MineMinXMRBalance(t *testing.T, wc WalletClient, minBalance *coins.PiconeroAmount)

MineMinXMRBalance enables mining for the passed wc wallet until it has an unlocked balance greater than or equal to minBalance.

func TestBackgroundMineBlocks

func TestBackgroundMineBlocks(t *testing.T)

TestBackgroundMineBlocks starts a background go routine to mine blocks in a monerod instance that is in regtest mode. If there is an existing go routine that is already mining from a previous call, no new go routine is created.

func WaitForBlocks

func WaitForBlocks(ctx context.Context, client WalletClient, count int) (uint64, error)

WaitForBlocks waits for `count` new blocks to arrive. It returns the height of the chain.

Types

type WalletClient

type WalletClient interface {
	GetAccounts() (*wallet.GetAccountsResponse, error)
	GetAddress(idx uint32) (*wallet.GetAddressResponse, error)
	PrimaryAddress() *mcrypto.Address
	GetBalance(idx uint32) (*wallet.GetBalanceResponse, error)
	Transfer(
		ctx context.Context,
		to *mcrypto.Address,
		accountIdx uint32,
		amount *coins.PiconeroAmount,
		numConfirmations uint64,
	) (*wallet.Transfer, error)
	SweepAll(
		ctx context.Context,
		to *mcrypto.Address,
		accountIdx uint32,
		numConfirmations uint64,
	) ([]*wallet.Transfer, error)
	CreateWalletConf(walletNamePrefix string) *WalletClientConf
	WalletName() string
	GetHeight() (uint64, error)
	Endpoint() string // URL on which the wallet is accepting RPC requests
	Close()           // Close closes the client itself, including any open wallet
	CloseAndRemoveWallet()
}

WalletClient represents a monero-wallet-rpc client.

func CreateSpendWalletFromKeys

func CreateSpendWalletFromKeys(
	conf *WalletClientConf,
	privateKeyPair *mcrypto.PrivateKeyPair,
	restoreHeight uint64,
) (WalletClient, error)

CreateSpendWalletFromKeys creates a new monero-wallet-rpc process, wallet client and spend wallet for the passed private key pair (view key and spend key).

func CreateViewOnlyWalletFromKeys

func CreateViewOnlyWalletFromKeys(
	conf *WalletClientConf,
	privateViewKey *mcrypto.PrivateViewKey,
	address *mcrypto.Address,
	restoreHeight uint64,
) (WalletClient, error)

CreateViewOnlyWalletFromKeys creates a new monero-wallet-rpc process, wallet client and view-only wallet for the passed private view key and address.

func CreateWalletClient

func CreateWalletClient(t *testing.T) WalletClient

CreateWalletClient starts a monero-wallet-rpc listening on a random port for tests and returns the client interface for using it. Background mining is initiated so created transactions get mined into blocks.

func CreateWalletClientWithWalletDir

func CreateWalletClientWithWalletDir(t *testing.T, walletDir string) WalletClient

CreateWalletClientWithWalletDir creates a WalletClient with the given wallet directory.

func NewThinWalletClient

func NewThinWalletClient(monerodHost string, monerodPort uint, walletPort uint) WalletClient

NewThinWalletClient returns a WalletClient for an existing monero-wallet-rpc process.

func NewWalletClient

func NewWalletClient(conf *WalletClientConf) (WalletClient, error)

NewWalletClient returns a WalletClient for a newly created monero-wallet-rpc process.

type WalletClientConf

type WalletClientConf struct {
	Env                 common.Environment   // Required
	WalletFilePath      string               // Required, wallet created if it does not exist
	WalletPassword      string               // Optional, password used to open wallet or when creating a new wallet
	WalletPort          uint                 // Optional, zero means OS picks a random port
	MonerodNodes        []*common.MoneroNode // Optional, defaulted from environment if nil
	MoneroWalletRPCPath string               // optional, path to monero-rpc-binary
	LogPath             string               // optional, default is dir(WalletFilePath)/../monero-wallet-rpc.log
}

WalletClientConf wraps the configuration fields needed to call NewWalletClient

func (*WalletClientConf) Fill

func (conf *WalletClientConf) Fill() error

Fill fills in the optional configuration values (Port, MonerodNodes, MoneroWalletRPCPath, and LogPath) if they are not set. Note: MonerodNodes is set to the first validated node.

Jump to

Keyboard shortcuts

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