Skip to content

Commit

Permalink
improve docs for TxBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-volz committed Aug 4, 2023
1 parent 751301f commit b935cc8
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions defichain/transactions/builder/txbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,36 @@

class TxBuilder:
"""
This it the main class to build transactions. The transaction will be built with the information provided and
automatically signed.
**This it the main class to build transactions!**
The transaction will be built with the information provided and automatically signed.
All transactions are created for the given address.
The account parameter must match the given address and contains the matching private key.
Through the given data source, all the necessary information is pulled from the blockchain which is
required to create the transaction. The standard data source is the ocean infrastructure.
However, this can also be replaced by a Defichain node connection.
required to create the transaction. The suggested data source is the ocean infrastructure.
However, this can also be replaced by a defichain node connection.
If no data source is specified, the appropriate inputs must be passed to the individual methods.
By default, a fee of one satoshi per byte is used.
Input Handling:
All inputs of an address are always combined to one output.
All inputs of an address are always combined to one output.
>>> # Import ocean, wallet, network and txbuilder
>>> from defichain import Ocean
>>> from defichain import Wallet
>>> from defichain.networks import DefichainMainnet
>>> from defichain import TxBuilder
>>> # Specify ocean connection
>>> ocean = Ocean(network="mainnet")
>>> # Create wallet and account
>>> mnemonic = "avocado key fan step egg engage winter upper attitude carry regret mixed utility body party trip valid oppose gas ensure deputy suspect blur trade"
>>> wallet = Wallet(DefichainMainnet)
>>> wallet.from_mnemonic(mnemonic)
>>> account = wallet.get_account(0)
>>> # Create TxBuilder
>>> builder = TxBuilder(account.get_p2wpkh(), account, ocean)
:param address: (required) address for which the transaction is created
:type address: str
Expand Down Expand Up @@ -70,7 +85,7 @@ def send_tx(self, tx: "Transaction | str", maxFeeRate: float = None) -> str:
:type tx: Transaction | str
:param maxFeeRate: (optional) maximum fee rate
:type maxFeeRate: float
:return: "hex" (str) - the transaction hash
:return: "hex" (str) - transaction hash (txid)
"""
if self.get_dataSource() is not None:
if isinstance(tx, Transaction):
Expand Down Expand Up @@ -126,31 +141,31 @@ def get_inputs_tx(self) -> Transaction:
# Get Information
def get_address(self) -> str:
"""
Returns the address specified in the builder
Returns the address specified in the builder object
:return: address (str)
"""
return self._address

def get_account(self) -> Account:
"""
Returns the account specified in the builder
Returns the account specified in the builder object
:return: Account
"""
return self._account

def get_dataSource(self) -> "RemoteData":
def get_dataSource(self) -> "RemoteDataOcean | RemoteDataNode | None":
"""
Returns the data source specified in the builder
Returns the data source specified in the builder object
:return: RemoteData
"""
return self._dataSource

def get_feePerByte(self) -> float:
"""
Returns the fee per byte specified in the builder
Returns the fee per byte specified in the builder object
:return: float
"""
Expand Down

0 comments on commit b935cc8

Please sign in to comment.