- Struct
ScriptBuf
- Constants
- Function
empty
- Function
new
- Function
single
- Function
new_p2pkh
- Function
new_p2sh
- Function
script_pubkey
- Function
match_script_pubkey
- Function
is_empty
- Function
bytes
- Function
into_bytes
- Function
is_p2sh
- Function
p2sh_script_hash
- Function
is_p2pkh
- Function
p2pkh_pubkey_hash
- Function
is_witness_program
- Function
witness_program
- Function
is_op_return
- Function
push_opcode
- Function
push_data
- Function
push_int
- Function
push_key
- Function
push_x_only_key
use 0x1::vector;
use 0x3::bitcoin_address;
use 0x4::opcode;
#[data_struct]
struct ScriptBuf has copy, drop, store
const BITCOIN_PUBKEY_HASH_SIZE: u64 = 20;
const BITCOIN_PUBKEY_SIZE: u64 = 33;
const BITCOIN_SCRIPT_HASH_SIZE: u64 = 20;
const BITCOIN_X_ONLY_PUBKEY_SIZE: u64 = 32;
const ErrorInvalidKeySize: u64 = 1;
const ErrorInvalidPubkeyHash: u64 = 3;
const ErrorInvalidScriptHash: u64 = 4;
const ErrorNumberOverflow: u64 = 2;
const I64_MAX: u64 = 9223372036854775807;
public fun empty(): script_buf::ScriptBuf
public fun new(bytes: vector<u8>): script_buf::ScriptBuf
public fun single(opcode: u8): script_buf::ScriptBuf
public fun new_p2pkh(pubkey_hash: vector<u8>): script_buf::ScriptBuf
public fun new_p2sh(script_hash: vector<u8>): script_buf::ScriptBuf
Generates a script pubkey spending to this address.
public fun script_pubkey(addr: &bitcoin_address::BitcoinAddress): script_buf::ScriptBuf
Returns true if the address creates a particular script
public fun match_script_pubkey(addr: &bitcoin_address::BitcoinAddress, sb: &script_buf::ScriptBuf): bool
public fun is_empty(self: &script_buf::ScriptBuf): bool
public fun bytes(self: &script_buf::ScriptBuf): &vector<u8>
public fun into_bytes(self: script_buf::ScriptBuf): vector<u8>
Checks if the given script is a P2SH script.
public fun is_p2sh(self: &script_buf::ScriptBuf): bool
Get the script hash from a P2SH script. This function does not check if the script is a P2SH script, the caller must do that.
public fun p2sh_script_hash(self: &script_buf::ScriptBuf): vector<u8>
Checks if the given script is a P2PKH script.
public fun is_p2pkh(self: &script_buf::ScriptBuf): bool
Get the public key hash from a P2PKH script. This function does not check if the script is a P2PKH script, the caller must do that.
public fun p2pkh_pubkey_hash(self: &script_buf::ScriptBuf): vector<u8>
public fun is_witness_program(self: &script_buf::ScriptBuf): bool
Get the witness program from a witness program script.
public fun witness_program(self: &script_buf::ScriptBuf): vector<u8>
Checks if the given script is an OP_RETURN script.
public fun is_op_return(self: &script_buf::ScriptBuf): bool
public fun push_opcode(self: &mut script_buf::ScriptBuf, opcode: u8)
public fun push_data(self: &mut script_buf::ScriptBuf, data: vector<u8>)
Adds instructions to push an integer onto the stack.
Integers are encoded as little-endian signed-magnitude numbers, but there are dedicated opcodes to push some small integers. Because there no i64 type in Move, we use u64 to represent the integer. The value over the I64_MAX will abort, we can support negative value in the future.
public fun push_int(self: &mut script_buf::ScriptBuf, n: u64)
Push a Bitcoin public key to the script
public fun push_key(self: &mut script_buf::ScriptBuf, key: vector<u8>)
Push a Bitcoin x-only public key to the script
public fun push_x_only_key(self: &mut script_buf::ScriptBuf, key: vector<u8>)