Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
chore: htlcClaim builder (v2 & v3) improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Moustikitos committed Jun 6, 2022
1 parent 2239289 commit 0348355
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions dposlib/ark/builders/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dposlib import rest, cfg
from dposlib.ark import crypto, slots
from dposlib.ark.tx import Transaction
from dposlib.util.bin import hexlify
from dposlib.util.bin import hexlify, HEX


def transfer(amount, address, vendorField=None, expiration=0):
Expand Down Expand Up @@ -311,18 +311,20 @@ def htlcClaim(txid, secret):
Args:
txid (str): htlc lock transaction id.
secret (str): passphrase used by htlc lock transaction.
secret (str): passphrase or hash used by htlc lock transaction.
Returns:
dposlib.ark.tx.Transaction: orphan transaction.
"""
if not HEX.match(secret):
secret = hexlify(htlcSecret(secret))
return Transaction(
version=cfg.txversion,
type=9,
asset={
"claim": {
"lockTransactionId": txid,
"unlockSecret": hexlify(htlcSecret(secret))
"unlockSecret": secret
}
}
)
Expand Down
8 changes: 5 additions & 3 deletions dposlib/ark/builders/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dposlib import rest, cfg
from dposlib.ark import slots
from dposlib.ark.tx import Transaction
from dposlib.util.bin import hexlify
from dposlib.util.bin import hexlify, HEX


HtlcSecretHashType = {
Expand Down Expand Up @@ -154,20 +154,22 @@ def htlcClaim(txid, secret, hash_type=0):
Args:
txid (str): htlc lock transaction id.
secret (str): passphrase used by htlc lock transaction.
secret (str): passphrase or hash used by htlc lock transaction.
hash_type (int): hash method used.
Returns:
dposlib.ark.tx.Transaction: orphan transaction.
"""
if not HEX.match(secret):
secret = hexlify(htlcSecret(secret, hash_type))
return Transaction(
version=cfg.txversion,
type=9,
asset={
"claim": {
"hashType": hash_type,
"lockTransactionId": txid,
"unlockSecret": hexlify(htlcSecret(secret, hash_type))
"unlockSecret": secret
}
}
)
Expand Down

0 comments on commit 0348355

Please sign in to comment.