application

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CoinSelectionStrategySmallestSubset = iota
)

Variables

View Source
var (
	DefaultCoinSelector = ss_selector.NewSmallestSubsetCoinSelector()
	MinMillisatsPerByte = uint64(100)
)
View Source
var (
	ErrForbiddenUnlockedInputs = fmt.Errorf(
		"the utxos used within 'external' transactions must be coming from a " +
			"wallet's coin selection so that they can be temporary locked and " +
			"prevent to accidentally double spending them",
	)
)

Functions

This section is empty.

Types

type AccountInfo

type AccountInfo struct {
	domain.AccountInfo
}

type AccountService

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

AccountService is responsible for operations related to wallet accounts:

  • Create a new account.
  • Derive addresses for an existing account.
  • List derived addresses for an existing account.
  • Get balance of an existing account.
  • List utxos of an existing account.
  • Delete an existing account.

The service registers 3 handlers related to the following wallet events:

  • domain.WalletAccountCreated - whenever an account is created, the service initializes a dedicated blockchain scanner and starts listening for its reports.
  • domain.WalletAccountAddressesDerived - whenever one or more addresses are derived for an account, they are added to the list of those watched by the account's scanner.
  • domain.WalletAccountDeleted - whenever an account is deleted, the relative scanner is stopped and removed.

The service guarantees to be always listening to notifications coming from each of its blockchain scanners in order to keep updated the utxo set of the relative accounts, ie. at startup it takes care of initializing a scanner for any existing account in case the wallet is already initialized and was just restarted.

func NewAccountService

func NewAccountService(
	repoManager ports.RepoManager, bcScanner ports.BlockchainScanner,
) *AccountService

func (*AccountService) CreateAccountBIP44

func (as *AccountService) CreateAccountBIP44(
	ctx context.Context, label string, unconf bool,
) (*AccountInfo, error)

func (*AccountService) DeleteAccount

func (as *AccountService) DeleteAccount(
	ctx context.Context, accountName string,
) (err error)

func (*AccountService) DeriveAddressesForAccount added in v0.1.3

func (as *AccountService) DeriveAddressesForAccount(
	ctx context.Context, accountName string, numOfAddresses uint64,
) (AddressesInfo, error)

func (*AccountService) DeriveChangeAddressesForAccount added in v0.1.3

func (as *AccountService) DeriveChangeAddressesForAccount(
	ctx context.Context, accountName string, numOfAddresses uint64,
) (AddressesInfo, error)

func (*AccountService) GetBalanceForAccount

func (as *AccountService) GetBalanceForAccount(
	ctx context.Context, accountName string,
) (BalanceInfo, error)

func (*AccountService) ListAddressesForAccount

func (as *AccountService) ListAddressesForAccount(
	ctx context.Context, accountName string,
) (AddressesInfo, error)

func (*AccountService) ListUtxosForAccount

func (as *AccountService) ListUtxosForAccount(
	ctx context.Context, accountName string,
) (*UtxoInfo, error)

func (*AccountService) SetAccountLabel added in v0.1.16

func (as *AccountService) SetAccountLabel(
	ctx context.Context, accountName, label string,
) (*AccountInfo, error)

type AddressesInfo

type AddressesInfo []domain.AddressInfo

func (AddressesInfo) Addresses

func (info AddressesInfo) Addresses() []string

type BalanceInfo

type BalanceInfo map[string]*domain.Balance

type BlockInfo

type BlockInfo struct {
	Hash      []byte
	Height    uint32
	Timestamp int64
}

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

type CoinSelectorFactory

type CoinSelectorFactory func() ports.CoinSelector

type Input

type Input struct {
	TxID          string
	VOut          uint32
	Script        string
	ScriptSigSize int
	WitnessSize   int
}

type Inputs

type Inputs []Input

func (Inputs) Keys added in v0.2.8

func (i Inputs) Keys() []domain.UtxoKey

type NotificationService

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

Notification service has the very simple task of making the event channels of the used domain.TransactionRepository and domain.UtxoRepository accessible by external clients so that they can get real-time updates on the status of the internal wallet.

func NewNotificationService

func NewNotificationService(
	repoManager ports.RepoManager, bcScanner ports.BlockchainScanner,
) *NotificationService

func (*NotificationService) GetTxChannel

func (ns *NotificationService) GetTxChannel(
	ctx context.Context,
) (chan domain.TransactionEvent, error)

func (*NotificationService) GetUtxoChannel

func (ns *NotificationService) GetUtxoChannel(
	ctx context.Context,
) (chan domain.UtxoEvent, error)

func (*NotificationService) StopWatchingScript added in v0.2.0

func (ns *NotificationService) StopWatchingScript(
	ctx context.Context, label string,
) error

func (*NotificationService) WatchScript added in v0.2.0

func (ns *NotificationService) WatchScript(
	ctx context.Context, scriptHex, blindingKey string,
) (string, error)

type Output

type Output struct {
	Asset        string
	Amount       uint64
	Script       []byte
	BlindingKey  []byte
	BlinderIndex uint32
}

func (Output) Validate

func (o Output) Validate() error

type Outputs

type Outputs []Output

type TransactionInfo

type TransactionInfo domain.Transaction

type TransactionService

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

TransactionService is responsible for operations related to one or more accounts:

  • Get info about a wallet-related transaction.
  • Select a subset of the utxos of an existing account to cover a target amount. The selected utxos will be temporary locked to prevent double spending them.
  • Estimate the fee amount for a transation composed by X inputs and Y outputs. It is required that the inputs owned by the wallet are locked utxos.
  • Sign a raw transaction (in hex format). It is required that the inputs of the tx owned by the wallet are locked utxos.
  • Broadcast a raw transaction (in hex format). It is required that the inputs of the tx owned by the wallet are locked utxos.
  • Create a partial transaction (v2) given a list of inputs and outputs. It is required that the inputs of the tx owned by the wallet are locked utxos.
  • Add inputs or outputs to partial transaction (v2). It is required that the inputs of the tx owned by the wallet are locked utxos.
  • Blind a partial transaction (v2) either as non-last or last blinder. It is required that the inputs of the tx owned by the wallet are locked utxos.
  • Sign a partial transaction (v2). It is required that the inputs of the tx owned by the wallet are locked utxos.
  • Craft a finalized transaction to transfer some funds from an existing account to somewhere else, given a list of outputs.

The service registers 1 handler for the following utxo event:

  • domain.UtxoLocked - whenever one or more utxos are locked, the service spawns a so-called unlocker, a goroutine wating for X seconds before unlocking them if necessary. The operation is just skipped if the utxos have been spent meanwhile.

The service guarantees that any locked utxo is eventually unlocked ASAP after the waiting time expires. Therefore, at startup, it makes sure to unlock any still-locked utxo that can be unlocked, and to spawn the required numnber of unlockers for those whose waiting time didn't expire yet.

func NewTransactionService

func NewTransactionService(
	repoManager ports.RepoManager, bcScanner ports.BlockchainScanner,
	net *network.Network, utxoExpiryDuration time.Duration, dustAmount uint64,
) *TransactionService

func (*TransactionService) BlindPset

func (ts *TransactionService) BlindPset(
	ctx context.Context,
	ptx string, extraUnblindedInputs []UnblindedInput, lastBlinder bool,
) (string, error)

func (*TransactionService) BroadcastTransaction

func (ts *TransactionService) BroadcastTransaction(
	ctx context.Context, txHex string,
) (string, error)

func (*TransactionService) CreatePset

func (ts *TransactionService) CreatePset(
	ctx context.Context, inputs Inputs, outputs Outputs,
) (string, error)

func (*TransactionService) EstimateFees

func (ts *TransactionService) EstimateFees(
	ctx context.Context, ins Inputs, outs Outputs, millisatsPerByte uint64,
) (uint64, error)

func (*TransactionService) GetTransactionInfo

func (ts *TransactionService) GetTransactionInfo(
	ctx context.Context, txid string,
) (*TransactionInfo, error)

func (*TransactionService) LockUtxos added in v0.2.8

func (ts *TransactionService) LockUtxos(
	ctx context.Context, accountName string, ins Inputs,
) (int64, error)

func (*TransactionService) SelectUtxos

func (ts *TransactionService) SelectUtxos(
	ctx context.Context, accountName, targetAsset string, targetAmount uint64,
	coinSelectionStrategy int,
) (Utxos, uint64, int64, error)

func (*TransactionService) SignPset

func (ts *TransactionService) SignPset(
	ctx context.Context, ptx string, sighashType uint32,
) (string, error)

func (*TransactionService) SignPsetWithSchnorrKey added in v0.2.2

func (ts *TransactionService) SignPsetWithSchnorrKey(
	ctx context.Context, tx string, sighashType uint32,
) (string, error)

func (*TransactionService) SignTransaction

func (ts *TransactionService) SignTransaction(
	ctx context.Context, txHex string, sighashType uint32,
) (string, error)

func (*TransactionService) Transfer

func (ts *TransactionService) Transfer(
	ctx context.Context, accountName string, outputs Outputs,
	millisatsPerByte uint64,
) (string, error)

func (*TransactionService) UpdatePset

func (ts *TransactionService) UpdatePset(
	ctx context.Context, ptx string, inputs Inputs, outputs Outputs,
) (string, error)

type UnblindedInput added in v0.1.3

type UnblindedInput struct {
	Index         uint32
	Amount        uint64
	Asset         string
	AmountBlinder string
	AssetBlinder  string
}

type UtxoInfo

type UtxoInfo struct {
	Spendable Utxos
	Locked    Utxos
}

type UtxoKeys

type UtxoKeys []domain.UtxoKey

func (UtxoKeys) String

func (u UtxoKeys) String() string

type Utxos

type Utxos []*domain.Utxo

func (Utxos) Info

func (u Utxos) Info() []domain.UtxoInfo

func (Utxos) Keys

func (u Utxos) Keys() []domain.UtxoKey

type UtxosInfo

type UtxosInfo []domain.UtxoInfo

func (UtxosInfo) Keys

func (u UtxosInfo) Keys() []domain.UtxoKey

type WalletInfo

type WalletInfo struct {
	Network             string
	NativeAsset         string
	RootPath            string
	BirthdayBlockHash   string
	BirthdayBlockHeight uint32
	Accounts            []AccountInfo
	BuildInfo           BuildInfo
}

type WalletRestoreMessage added in v0.1.16

type WalletRestoreMessage struct {
	Message string
	Err     error
}

type WalletService

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

WalletService is responsible for operations related to the managment of the wallet:

  • Generate a new random 24-words mnemonic.
  • Create a new wallet from scratch with given mnemonic and locked with the given password.
  • Unlock the wallet with a password.
  • Change the wallet password. It requires the wallet to be locked.
  • Get the status of the wallet (initialized, unlocked, inSync).
  • Get non-sensiive (network, native asset) and possibly sensitive info (root path, master blinding key and basic accounts' info) about the wallet. Sensitive info are returned only if the wallet is unlocked.

This service doesn't register any handler for wallet events, rather it allows its users to register their handler to manage situations like the unlocking of the wallet (for example, check how the grpc service uses this feature).

func NewWalletService

func NewWalletService(
	repoManager ports.RepoManager, bcScanner ports.BlockchainScanner,
	rootPath string, net *network.Network, buildInfo BuildInfo,
) *WalletService

func (*WalletService) Auth added in v0.1.14

func (ws *WalletService) Auth(
	ctx context.Context,
	password string,
) (bool, error)

func (*WalletService) ChangePassword

func (ws *WalletService) ChangePassword(
	ctx context.Context, currentPassword, newPassword string,
) error

func (*WalletService) CreateWallet

func (ws *WalletService) CreateWallet(
	ctx context.Context, mnemonic []string, passphrase string,
) (err error)

func (*WalletService) GenSeed

func (ws *WalletService) GenSeed(ctx context.Context) ([]string, error)

func (*WalletService) GetInfo

func (ws *WalletService) GetInfo(ctx context.Context) (*WalletInfo, error)

func (*WalletService) GetStatus

func (ws *WalletService) GetStatus(_ context.Context) WalletStatus

func (*WalletService) Lock

func (ws *WalletService) Lock(
	ctx context.Context, password string,
) (err error)

func (*WalletService) RegisterHandlerForWalletEvent

func (ws *WalletService) RegisterHandlerForWalletEvent(
	eventType domain.WalletEventType, handler ports.WalletEventHandler,
)

func (*WalletService) RestoreWallet

func (ws *WalletService) RestoreWallet(
	ctx context.Context, chMessages chan WalletRestoreMessage,
	mnemonic []string, rootPath, passpharse string,
	birthdayBlockHeight, emptyAccountsThreshold, unusedAddressesThreshold uint32,
)

func (*WalletService) Unlock

func (ws *WalletService) Unlock(
	ctx context.Context, password string,
) (err error)

type WalletStatus

type WalletStatus struct {
	IsInitialized bool
	IsUnlocked    bool
	IsSynced      bool
}

Jump to

Keyboard shortcuts

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