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
- 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.
 - Use extended key format to create string policies. More on policies.
 - Use the compile function to get a deposit_descriptor.
 - Use wallet functions by passing your deposit_descriptor and node_address as primary inputss.
 - Electrum over ssl is the recommended way to interact with the wallet with format of ‘ssl://electrum.blockstream.info:60002’.
 - “default” can be used as a string for the node_address which will use Blockstream servers. Recommened client to use tor with this setting.
 - Bitcoin-core RPC is supported but not advised unless on desktop where a node is connected to locally.
 - Core RPC (currently) requies node_address to follow the format of ‘https://address:port?auth=username:password’.
 - Outputs of each function are JSON stringified native structs specified as ‘FFI Outputs’ in under module documentation.
 - Use every function in combination with cstring_free to free their output pointers. This will keep things safe.
 
Building a transaction
- Build a transaction with a default fixed fee of 1000 sats
 - Get weight of the transaction for a given descriptor
 - Use get absolute fee to get the fee needed to be paid for the transaction given variable fee rate and fixed weight.
 - 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.
Convert days to bitcoin blocks as height. Does not consider the current block height. Add to get_height to get the expected block height after the given time in days.
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 current block height.
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.