Skip to content

Commit

Permalink
improve docs for utxo
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-volz committed Aug 4, 2023
1 parent b935cc8 commit 6f9c54a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
36 changes: 27 additions & 9 deletions defichain/transactions/builder/modules/utxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,44 @@


class UTXO:
"""
**The methods of this module are responsible for sending UTXO to different addresses.**
You can do that three on different ways:
1. send: send just one specified amount from the builder address to another address
2. sendall: send all utxo from the builder address to another address
3. sendmany: send specified amounts from the builder address to multiple different addresses.
"""

def __init__(self, builder):
self._builder: RawTransactionBuilder = builder

def send(self, value: "float | int", addressTo: str, changeAddress: str = None, inputs=[]) -> Transaction:
def send(self, amount: "float | int", addressTo: str, changeAddress: str = None, inputs=[]) -> Transaction:
"""
Sends the specified amount of UTXO to the specified address. Returns the remaining UTXO from the input to the
sender address if not changed.
Sends the specified amount of UTXO to the specified address.
:param value: (required) amount of UTXO to send
:type value: float | int
Returns the remaining UTXO from the input to the sender address if not changed.
>>> builder.utxo.send(1, "df1qw8c57c3c4u7k2h4gv2d5x4jr4qgq6cugg33g6e") # sends one UTXO DFI to the specified address
:param amount: (required) amount of UTXO to send
:type amount: float | int
:param addressTo: (required) address to send the UTXO to
:type addressTo: str
:param changeAddress: (optional) address to which the remaining UTXO should be sent
:type changeAddress: str
:param inputs: (optional) Inputs
:type inputs: TxInputs
:type inputs: TxInput
:return: Transaction
"""
if changeAddress is None:
changeAddress = self._builder.get_address()

# Convert Float to Integer
value = Converter.float_to_int(value)
value = Converter.float_to_int(amount)

# If to_address is the same as account address
if addressTo == self._builder.get_address() or addressTo == changeAddress:
Expand Down Expand Up @@ -59,6 +73,8 @@ def sendall(self, addressTo: str, inputs=[]) -> Transaction:
"""
Sends all UTXO to the specified address
>>> builder.utxo.sendall("df1qw8c57c3c4u7k2h4gv2d5x4jr4qgq6cugg33g6e") # sends all UTXO DFI to the specified address
:param addressTo: (required) address to send the UTXO to
:type addressTo: str
:param inputs: (optional) Inputs
Expand Down Expand Up @@ -87,8 +103,10 @@ def sendmany(self, addressAmountTo: {}, changeAddress=None, inputs=[]) -> Transa
Sends the specified amount of UTXO to the specified addresses. Returns the remaining UTXO from the input to the
sender address if not changed.
:param addressAmountTo: (required) AddressAmount
:type addressAmountTo: json string
>>> builder.utxo.sendmany({"df1qw8c57c3c4u7k2h4gv2d5x4jr4qgq6cugg33g6e": "1@DFI", "df1qzfwy63ggj5jfpul7r04kn2ss8kjz2sda57fa4m": "1@DFI"}) # sends each address one UTXO DFI
:param addressAmountTo: (required) json with specified address and amount to send
:type addressAmountTo: :ref:`Transactions AddressAmount`
:param changeAddress: (required) address to which the remaining UTXO should be sent
:type changeAddress: str
:param inputs: (optional) Inputs
Expand Down
1 change: 0 additions & 1 deletion defichain/transactions/builder/txbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from defichain.exceptions.transactions import TxBuilderError

from defichain.transactions.remotedata.remotedata import RemoteData
from defichain.transactions.remotedata import RemoteDataOcean, RemoteDataNode

from .rawtransactionbuilder import RawTransactionBuilder
Expand Down
7 changes: 6 additions & 1 deletion docs/source/sdk/transactions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ Transactions
:maxdepth: 1
:hidden:

exceptions
exceptions

.. _Transactions AddressAmount:

AddressAmount
-------------

0 comments on commit 6f9c54a

Please sign in to comment.