Transaction
XinFin transaction in blockchain network.
- class swap.providers.xinfin.transaction.Transaction(network: str = 'mainnet', xrc20: bool = False, provider: str = 'http')
XinFin Transaction.
- Parameters
network (str) – XinFin network, defaults to
mainnet
.xrc20 (bool) – Transaction XRC20 token, default to
False
.provider (str) – XinFin network provider, defaults to
http
.
- Returns
Transaction – XinFin transaction instance.
Note
XinFin has only three networks,
mainnet
,apothem
andtestnet
.- fee(unit: str = 'Wei') Union[Wei, int, float]
Get XinFin transaction fee.
- Parameters
unit (str) – XinFin unit, default to
Wei
.- Returns
Wei, int, float – XinFin transaction fee.
>>> from swap.providers.xinfin.htlc import HTLC >>> from swap.providers.xinfin.transaction import FundTransaction >>> from swap.utils import sha256, get_current_timestamp >>> htlc: HTLC = HTLC(contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7", network="testnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", sender_address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", endtime=get_current_timestamp(plus=3600)) >>> fund_transaction: FundTransaction = FundTransaction(network="testnet") >>> fund_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", htlc=htlc, amount=3, unit="XDC") >>> fund_transaction.fee(unit="Wei") 138436
- hash() Optional[str]
Get XinFin transaction hash.
- Returns
str – XinFin transaction hash.
>>> from swap.providers.xinfin.transaction import WithdrawTransaction >>> from swap.providers.xinfin.solver import WithdrawSolver >>> withdraw_transaction: WithdrawTransaction = WithdrawTransaction(network="testnet") >>> withdraw_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", secret_key="Hello Meheret!", address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") >>> withdraw_solver: WithdrawSolver = WithdrawSolver(xprivate_key="xprv9s21ZrQH143K4Kpce43z5guPyxLrFoc2i8aQAq835Zzp4Rt7i6nZaMCnVSDyHT6MnmJJGKHMrCUqaYpGojrug1ZN5qQDdShQffmkyv5xyUR", path="m/44'/550'/0'/0/0") >>> withdraw_transaction.sign(solver=withdraw_solver) >>> withdraw_transaction.hash() "0xe8e8738c791385738661573ad4de63dd81b77d240b6138ca476ea8cdcbb29a21"
- json() dict
Get XinFin transaction fee.
- Returns
Wei, int, float – XinFin transaction fee.
>>> from swap.providers.xinfin.htlc import HTLC >>> from swap.providers.xinfin.transaction import FundTransaction >>> from swap.utils import sha256, get_current_timestamp >>> htlc: HTLC = HTLC(contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7", network="testnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", sender_address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", endtime=get_current_timestamp(plus=3600)) >>> fund_transaction: FundTransaction = FundTransaction(network="testnet") >>> fund_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", htlc=htlc, amount=3, unit="XDC") >>> fund_transaction.json() {'chainId': 1337, 'from': '0x2224caA2235DF8Da3D2016d2AB1137D2d548A232', 'value': 3000000000000000000, 'nonce': 2, 'gas': 138436, 'gasPrice': 20000000000, 'to': '0xdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7', 'data': '0xf4fd30623a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb000000000000000000000000f8d43806260cfc6cc79fb408ba1897054667f81c0000000000000000000000002224caa2235df8da3d2016d2ab1137d2d548a2320000000000000000000000000000000000000000000000000000000060e000d3'}
- raw() Optional[str]
Get XinFin transaction hash.
- Returns
str – XinFin transaction hash.
>>> from swap.providers.xinfin.transaction import RefundTransaction >>> from swap.providers.xinfin.solver import RefundSolver >>> refund_transaction: RefundTransaction = RefundTransaction(network="testnet") >>> refund_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") >>> refund_solver: RefundSolver = RefundSolver(xprivate_key="xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj", path="m/44'/550'/0'/0/0") >>> refund_transaction.sign(solver=refund_solver) >>> refund_transaction.hash() "0xf88a028504a817c80082e76094de06b10c67765c8c0b9f64e0ef423b45eb86b8e780a47249fbb61909575c436a0eabe6caa72d4feb2c4aeceef586fe94ca82f36ce9c20efda4b4820a95a05ed63e467fb541b728dc7253ea4f9c4f2ada130ef78ffaba8de9c5e92536ce42a034ba97172cb8726cdfbaba14b10a817a0c4c4bccc6d8f2a27fc1711752ed2ab2"
- type() str
Get XinFin transaction hash.
- Returns
str – XinFin transaction hash.
>>> from swap.providers.xinfin.transaction import WithdrawTransaction >>> from swap.providers.xinfin.solver import WithdrawSolver >>> withdraw_transaction: WithdrawTransaction = WithdrawTransaction(network="testnet") >>> withdraw_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", secret_key="Hello Meheret!", address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") >>> withdraw_transaction.type() "xinfin_withdraw_unsigned"
- signature() dict
Get XinFin transaction hash.
- Returns
str – XinFin transaction hash.
>>> from swap.providers.xinfin.transaction import RefundTransaction >>> from swap.providers.xinfin.solver import RefundSolver >>> refund_transaction: RefundTransaction = RefundTransaction(network="testnet") >>> refund_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") >>> refund_solver: RefundSolver = RefundSolver(xprivate_key="xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj", path="m/44'/550'/0'/0/0") >>> refund_transaction.sign(solver=refund_solver) >>> refund_transaction.signature() {'hash': '0x90449ab8e3736feae4980554bb129b408f88d0003e569022cf8e00817cc2a7d9', 'rawTransaction': '0xf88a028504a817c80082e76094de06b10c67765c8c0b9f64e0ef423b45eb86b8e780a47249fbb61909575c436a0eabe6caa72d4feb2c4aeceef586fe94ca82f36ce9c20efda4b4820a95a05ed63e467fb541b728dc7253ea4f9c4f2ada130ef78ffaba8de9c5e92536ce42a034ba97172cb8726cdfbaba14b10a817a0c4c4bccc6d8f2a27fc1711752ed2ab2', 'r': 42895942847608608192932856733711858695420995837709512084644654454168196927042, 's': 23849944468865388317715121201379699989753020274517556595896033163737398323890, 'v': 2709}
- transaction_raw() str
Get XinFin fund transaction raw.
- Returns
str – XinFin fund transaction raw.
>>> from swap.providers.xinfin.htlc import HTLC >>> from swap.providers.xinfin.transaction import FundTransaction >>> from swap.utils import sha256, get_current_timestamp >>> htlc: HTLC = HTLC(contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7", network="testnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", sender_address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", endtime=get_current_timestamp(plus=3600)) >>> fund_transaction: FundTransaction = FundTransaction(network="testnet") >>> fund_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", htlc=htlc, amount=3, unit="XDC") >>> fund_transaction.transaction_raw() "eyJmZWUiOiAxMzg0MzYsICJ0eXBlIjogInhpbmZpbl9mdW5kX3Vuc2lnbmVkIiwgInRyYW5zYWN0aW9uIjogeyJjaGFpbklkIjogMTMzNywgImZyb20iOiAiMHgyMjI0Y2FBMjIzNURGOERhM0QyMDE2ZDJBQjExMzdEMmQ1NDhBMjMyIiwgInZhbHVlIjogMzAwMDAwMDAwMDAwMDAwMDAwMCwgIm5vbmNlIjogMiwgImdhcyI6IDEzODQzNiwgImdhc1ByaWNlIjogMjAwMDAwMDAwMDAsICJ0byI6ICIweGRFMDZiMTBjNjc3NjVjOEMwYjlGNjRFMGVGNDIzYjQ1RWI4NmI4ZTciLCAiZGF0YSI6ICIweGY0ZmQzMDYyM2EyNmRhODJlYWQxNWE4MDUzM2EwMjY5NjY1NmIxNGI1ZGJmZDg0ZWIxNDc5MGYyZTFiZTVlOWU0NTgyMGVlYjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMGY4ZDQzODA2MjYwY2ZjNmNjNzlmYjQwOGJhMTg5NzA1NDY2N2Y4MWMwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAyMjI0Y2FhMjIzNWRmOGRhM2QyMDE2ZDJhYjExMzdkMmQ1NDhhMjMyMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA2MGUwMDBkMyJ9LCAic2lnbmF0dXJlIjogbnVsbCwgIm5ldHdvcmsiOiAidGVzdG5ldCJ9"
NormalTransaction
- class swap.providers.xinfin.transaction.NormalTransaction(network: str = 'mainnet', xrc20: bool = False, provider: str = 'http')
XinFin Normal transaction.
- Parameters
network (str) – XinFin network, defaults to
mainnet
.xrc20 (bool) – Normal transaction XRC20 token, default to
False
.provider (str) – XinFin network provider, defaults to
http
.
- Returns
NormalTransaction – XinFin normal transaction instance.
Warning
Do not forget to build transaction after initialize fund transaction.
- build_transaction(address: str, recipient: dict, token_address: Optional[str] = None, unit: str = 'Wei') swap.providers.xinfin.transaction.NormalTransaction
Build XinFin normal transaction.
- Parameters
address (str) – XinFin sender address.
recipient (dict) – Recipients XinFin address and amount.
token_address (bool) – XinFin XRC20 token address, default to
None
.unit (str) – XinFin unit, default to
Wei
.
- Returns
NormalTransaction – XinFin normal transaction instance.
>>> from swap.providers.xinfin.transaction import NormalTransaction >>> normal_transaction: NormalTransaction = NormalTransaction(network="testnet") >>> normal_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", recipient={"xdcf8D43806260CFc6cC79fB408BA1897054667F81C": 100_000_000}) <swap.providers.xinfin.transaction.FundTransaction object at 0x0409DAF0>
- sign(solver: swap.providers.xinfin.solver.NormalSolver) swap.providers.xinfin.transaction.NormalTransaction
Sign XinFin normal transaction.
- Parameters
solver (xinfin.solver.NormalSolver) – XinFin normal solver.
- Returns
NormalTransaction – XinFin normal transaction instance.
>>> from swap.providers.xinfin.transaction import NormalTransaction >>> from swap.providers.xinfin.solver import NormalSolver >>> normal_transaction: NormalTransaction = NormalTransaction(network="testnet") >>> normal_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", recipient={"xdcf8D43806260CFc6cC79fB408BA1897054667F81C": 100_000_000}) >>> normal_solver: NormalSolver = NormalSolver(xprivate_key="xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj", address=0) >>> normal_transaction.sign(solver=normal_solver) <swap.providers.xinfin.transaction.FundTransaction object at 0x0409DAF0>
FundTransaction
- class swap.providers.xinfin.transaction.FundTransaction(network: str = 'mainnet', xrc20: bool = False, provider: str = 'http')
XinFin Fund transaction.
- Parameters
network (str) – XinFin network, defaults to
mainnet
.xrc20 (bool) – Fund transaction XRC20 token, default to
False
.provider (str) – XinFin network provider, defaults to
http
.
- Returns
FundTransaction – XinFin fund transaction instance.
Warning
Do not forget to build transaction after initialize fund transaction.
- build_transaction(address: str, htlc: swap.providers.xinfin.htlc.HTLC, amount: Union[Wei, int, float], unit: str = 'Wei') swap.providers.xinfin.transaction.FundTransaction
Build XinFin fund transaction.
- Parameters
htlc (xinfin.htlc.HTLC) – XinFin HTLC instance.
address (str) – XinFin sender address.
amount (Wei, int, float) – XinFin amount or XRC20 amount.
unit (str) – XinFin unit, default to
Wei
.
- Returns
FundTransaction – XinFin fund transaction instance.
>>> from swap.providers.xinfin.htlc import HTLC >>> from swap.providers.xinfin.transaction import FundTransaction >>> from swap.utils import sha256, get_current_timestamp >>> htlc: HTLC = HTLC(contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7", network="testnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", sender_address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", endtime=get_current_timestamp(plus=3600)) >>> fund_transaction: FundTransaction = FundTransaction(network="testnet") >>> fund_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", htlc=htlc, amount=3, unit="XDC") <swap.providers.xinfin.transaction.FundTransaction object at 0x0409DAF0>
- sign(solver: swap.providers.xinfin.solver.FundSolver) swap.providers.xinfin.transaction.FundTransaction
Sign XinFin fund transaction.
- Parameters
solver (xinfin.solver.FundSolver) – XinFin fund solver.
- Returns
FundTransaction – XinFin fund transaction instance.
>>> from swap.providers.xinfin.htlc import HTLC >>> from swap.providers.xinfin.transaction import FundTransaction >>> from swap.providers.xinfin.solver import FundSolver >>> from swap.utils import sha256, get_current_timestamp >>> htlc: HTLC = HTLC(contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7", network="testnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", sender_address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", endtime=get_current_timestamp(plus=3600)) >>> fund_transaction: FundTransaction = FundTransaction(network="testnet") >>> fund_transaction.build_transaction(address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", htlc=htlc, amount=3, unit="XDC") >>> fund_solver: FundSolver = FundSolver(xprivate_key="xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj", path="m/44'/550'/0'/0/0") >>> fund_transaction.sign(solver=fund_solver) <swap.providers.xinfin.transaction.FundTransaction object at 0x0409DAF0>
WithdrawTransaction
- class swap.providers.xinfin.transaction.WithdrawTransaction(network: str = 'mainnet', xrc20: bool = False, provider: str = 'http')
XinFin Withdraw transaction.
- Parameters
network (str) – XinFin network, defaults to
mainnet
.xrc20 (bool) – Withdraw transaction XRC20 token, default to
False
.provider (str) – XinFin network provider, defaults to
http
.
- Returns
WithdrawTransaction – XinFin withdraw transaction instance.
Warning
Do not forget to build transaction after initialize withdraw transaction.
- build_transaction(transaction_hash: str, address: str, secret_key: str, contract_address: Optional[str] = None) swap.providers.xinfin.transaction.WithdrawTransaction
Build XinFin withdraw transaction.
- Parameters
transaction_hash (str) – XinFin HTLC funded transaction hash.
address (str) – XinFin recipient address.
secret_key (str) – Secret password/passphrase.
contract_address (str) – XinFin HTLC contract address, defaults to
None
.
- Returns
WithdrawTransaction – XinFin withdraw transaction instance.
>>> from swap.providers.xinfin.transaction import WithdrawTransaction >>> withdraw_transaction: WithdrawTransaction = WithdrawTransaction(network="testnet") >>> withdraw_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", secret_key="Hello Meheret!", address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") <swap.providers.xinfin.transaction.WithdrawTransaction object at 0x0409DAF0>
- sign(solver: swap.providers.xinfin.solver.WithdrawSolver) swap.providers.xinfin.transaction.WithdrawTransaction
Sign XinFin withdraw transaction.
- Parameters
solver (xinfin.solver.WithdrawSolver) – XinFin withdraw solver.
- Returns
WithdrawTransaction – XinFin withdraw transaction instance.
>>> from swap.providers.xinfin.transaction import WithdrawTransaction >>> from swap.providers.xinfin.solver import WithdrawSolver >>> withdraw_transaction: WithdrawTransaction = WithdrawTransaction(network="testnet") >>> withdraw_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", secret_key="Hello Meheret!", address="xdcf8D43806260CFc6cC79fB408BA1897054667F81C", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") >>> withdraw_solver: WithdrawSolver = WithdrawSolver(xprivate_key="xprv9s21ZrQH143K4Kpce43z5guPyxLrFoc2i8aQAq835Zzp4Rt7i6nZaMCnVSDyHT6MnmJJGKHMrCUqaYpGojrug1ZN5qQDdShQffmkyv5xyUR", path="m/44'/550'/0'/0/0") >>> withdraw_transaction.sign(solver=withdraw_solver) <swap.providers.xinfin.transaction.WithdrawTransaction object at 0x0409DAF0>
RefundTransaction
- class swap.providers.xinfin.transaction.RefundTransaction(network: str = 'mainnet', xrc20: bool = False, provider: str = 'http')
XinFin Refund transaction.
- Parameters
network (str) – XinFin network, defaults to
mainnet
.xrc20 (bool) – Refund transaction XRC20 token, default to
False
.provider (str) – XinFin network provider, defaults to
http
.
- Returns
RefundTransaction – XinFin refund transaction instance.
Warning
Do not forget to build transaction after initialize refund transaction.
- build_transaction(transaction_hash: str, address: str, contract_address: Optional[str] = None) swap.providers.xinfin.transaction.RefundTransaction
Build XinFin refund transaction.
- Parameters
transaction_hash (str) – XinFin HTLC funded transaction hash.
address (str) – XinFin sender address.
contract_address (str) – XinFin HTLC contract address, defaults to
None
.
- Returns
RefundTransaction – XinFin refund transaction instance.
>>> from swap.providers.xinfin.transaction import RefundTransaction >>> refund_transaction: RefundTransaction = RefundTransaction(network="testnet") >>> refund_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") <swap.providers.xinfin.transaction.RefundTransaction object at 0x0409DAF0>
- sign(solver: swap.providers.xinfin.solver.RefundSolver) swap.providers.xinfin.transaction.RefundTransaction
Sign XinFin refund transaction.
- Parameters
solver (xinfin.solver.RefundSolver) – XinFin refund solver.
- Returns
RefundTransaction – XinFin refund transaction instance.
>>> from swap.providers.xinfin.transaction import RefundTransaction >>> from swap.providers.xinfin.solver import RefundSolver >>> refund_transaction: RefundTransaction = RefundTransaction(network="testnet") >>> refund_transaction.build_transaction(transaction_hash="0x0d4c93546aa3e5e476455931a63f1a97a2624e3b516e3fd8e3a582cb20aaeef9", address="xdc2224caA2235DF8Da3D2016d2AB1137D2d548A232", contract_address="xdcdE06b10c67765c8C0b9F64E0eF423b45Eb86b8e7") >>> refund_solver: RefundSolver = RefundSolver(xprivate_key="xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj", path="m/44'/550'/0'/0/0") >>> refund_transaction.sign(solver=refund_solver) <swap.providers.xinfin.transaction.RefundTransaction object at 0x0409DAF0>