TxUtils
bitcoinjs-lib / TxUtils
Class: TxUtils
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:39
Library for parsing and constructing transactions
Onchain
Extends
Constructors
new TxUtils()
new TxUtils(...
args
):TxUtils
Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:29
Parameters
args
...SupportedParamType
[]
Returns
Inherited from
Properties
args
args:
any
[] =[]
Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:28
Inherited from
artifact
static
artifact:Artifact
Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:15
Inherited from
NON_STATES_HASH_ROOT
readonly
static
NON_STATES_HASH_ROOT:ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:54
the state hash root value for all non-state inputs, same as hash160(hash160('') + hash160('') + hash160('') + hash160('') + hash160(''))
STATE_HASH_ROOT_SCRIPT_PREFIX
readonly
static
STATE_HASH_ROOT_SCRIPT_PREFIX:ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:47
op_return + op_push24 + "cat" (0x636174) + version (0x01)
stateType?
static
optional
stateType:string
Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:16
Inherited from
ZERO_SATS
readonly
static
ZERO_SATS:ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:43
if a output satoshi value is zero
Methods
buildChangeOutput()
static
buildChangeOutput(change
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:209
Build serialized change output
Parameters
change
change output to build
Returns
serialized change output in format ByteString
buildOpReturnOutput()
static
buildOpReturnOutput(data
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:238
build OP_RETURN
script from data payload
Parameters
data
the data payload
Returns
a ByteString contains the data payload
buildOutput()
static
buildOutput(script
,satoshis
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:175
Build serialized tx output
Parameters
script
serialized locking script of the output
satoshis
serialized satoshis of the output
Returns
serialized tx output in format ByteString
buildP2PKHOutput()
static
buildP2PKHOutput(addr
,amount
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:267
constructs a P2PKH output from a given PubKeyHash and satoshi amount
Parameters
addr
the recipient's public key hash
amount
the satoshi amount
Returns
a ByteString
representing the P2PKH output
buildP2PKHScript()
static
buildP2PKHScript(addr
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:249
constructs a P2PKH script from a given PubKeyHash
Parameters
addr
Returns
a ByteString
representing the P2PKH script
buildP2TROutput()
static
buildP2TROutput(xpubkey
,amount
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:309
constructs a p2tr output from a given PubKeyHash and satoshi amount
Parameters
xpubkey
the recipient's x-only public key
amount
the satoshi amount
Returns
a ByteString
representing the P2PKH output
buildP2TRScript()
static
buildP2TRScript(xpubkey
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:298
Parameters
xpubkey
Returns
buildP2WPKHOutput()
static
buildP2WPKHOutput(addr
,amount
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:288
constructs a P2WPKH output from a given PubKeyHash and satoshi amount
Parameters
addr
the recipient's public key hash
amount
the satoshi amount
Returns
a ByteString
representing the P2PKH output
buildP2WPKHScript()
static
buildP2WPKHScript(addr
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:277
Parameters
addr
Returns
buildStateHashRootOutput()
static
buildStateHashRootOutput(hashRoot
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:188
Build serialized state hash root output
Parameters
hashRoot
state hash root
Returns
serialized state hash root output in format ByteString
buildStateHashRootScript()
static
buildStateHashRootScript(hashRoot
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:198
Build locking script of state output from state hash root
Parameters
hashRoot
state hash root
Returns
locking script of state hash root output
checkIndex()
static
checkIndex(indexVal
,indexBytes
):void
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:164
Check if the index value and bytes are matched
Parameters
indexVal
value of the input index or output index
indexBytes
ByteString of the input index or output index
Returns
void
indexValueToBytes()
static
indexValueToBytes(indexVal
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:149
Convert tx input index or output index from value to bytes
Parameters
indexVal
value of the input index or output index
Returns
ByteString of the input index or output index
loadArtifact()
static
loadArtifact(artifact
): typeofSmartContractLib
Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:18
Parameters
artifact
Returns
typeof SmartContractLib
Inherited from
mergeInput()
static
mergeInput(txInput
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:221
Merge tx input into a ByteString
Parameters
txInput
tx input, must be a segwit input
Returns
serialized tx input
mergePrevouts()
static
mergePrevouts(prevouts
):MergePrevoutsResponse
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:64
Merge prevout list into a single ByteString
Parameters
prevouts
prevout list to merge
Returns
MergePrevoutsResponse
merged prevouts and number of tx inputs
mergeSpentAmounts()
static
mergeSpentAmounts(amounts
,t_inputCount
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:131
Merge spent amount list into a single ByteString
Parameters
amounts
spent amount list to merge
t_inputCount
bigint
the number of tx inputs, must be verified and trusable
Returns
merged spent amounts
mergeSpentScripts()
static
mergeSpentScripts(scripts
,t_inputCount
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:107
Merge spent script list into a single ByteString
Parameters
scripts
spent script list to merge
t_inputCount
bigint
the number of tx inputs, must be verified and trusable
Returns
merged spent scripts
toSatoshis()
static
toSatoshis(n
):ByteString
Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:319
convert a Int32
number to 8 bytes in little-end order.
Parameters
n
the satoshi amount
Returns
a ByteString