Crate stackmate[][src]

Expand description

Stackmate

A set of composite functions that uses rust-bitcoin & bdk and exposes a simplified C interface to build descriptor based wallets.

Workflow

  1. Use key functions generate_master/import_master and derive a parent key at a hardened path with a variable account number. Currently purpose is fixed at 84’ for segwit-native only.
  2. Use extended key format to create string policies. More on policies.
  3. Use the compile function to get a deposit_descriptor.
  4. Use wallet functions by passing your deposit_descriptor and node_address as primary inputss.
  5. Electrum over ssl is the recommended way to interact with the wallet with format of ‘ssl://electrum.blockstream.info:60002’.
  6. “default” can be used as a string for the node_address which will use Blockstream servers. Recommened client to use tor with this setting.
  7. Bitcoin-core RPC is supported but not advised unless on desktop where a node is connected to locally.
  8. Core RPC (currently) requies node_address to follow the format of ‘https://address:port?auth=username:password’.
  9. Outputs of each function are JSON stringified native structs specified as ‘FFI Outputs’ in under module documentation.
  10. Use every function in combination with cstring_free to free their output pointers. This will keep things safe.

Building a transaction

  1. Build a transaction with a default fixed fee of 1000 sats
  2. Get weight of the transaction for a given descriptor
  3. Use get absolute fee to get the fee needed to be paid for the transaction given variable fee rate and fixed weight.
  4. Build transaction with the absolute fee chosen, sign & broadcast.

Tor controls are in BETA. Use with caution.

Modules

Functions

Broadcasts a signed transaction to a remote node.

Builds a transaction for a given descriptor wallet. If sweep is set to true, amount value is ignored and will default to None. Set amount to 0 for sweep.

Checks if an extended public key is valid. Do not use the key source while checking an xpub i.e. remove [fingerprint/derivation/path/values] and only provide the xpub/tpub.

Compiles a policy into a descriptor of the specified script type. Use wpkh for a single signature segwit native wallet (default). Use wsh for a scripted segwit native wallet.

Switch on tor daemon. BETA: Careful with this.

Decodes a PSBT and returns all outputs of the transaction and total size. “miner” is used in the ‘to’ field of an output to indicate fee.

Derives hardened child keys from a master xprv. Follows the BIP32 standard of m/purpose’/network’/account’. Network path is inferred from the master xprv.

Gets the current network fee (in sats/vbyte) for a given confirmation target.

Converts a given absolute_fee (in sats) to fee rate (in sats/vbyte); given some transaction weight.

Converts a given fee_rate (in sats/vbyte) to absolute fee (in sats); given some transaction weight.

Generates a mnemonic phrase of a given length. Defaults to 24 words. A master xprv is created from the mnemonic and passphrase.

Gets a new address for a descriptor wallet at a given index. Client must keep track of address indexes and ENSURE prevention of address reuse.

Gets the weight of a transaction built with a given deposit-descriptor.

Creates a master xprv given a mnemonic and passphrase.

Signs a PSBT with a descriptor. Can only be used with descriptors containing private key(s).

Syncs to a remote node and fetches balance of a descriptor wallet.

Syncs to a remote node and fetches history of a descriptor wallet.