timo
December 14, 2022, 11:38am
6
According to that document P2WPKH, P2WSH, P2TR are all supported and they are bech32.
The limitation is not in the Bitcoin integration, it is only in the basic_bitcoin
example code. See here:
// the transaction.
//
// We solve this problem iteratively. We start with a fee of zero, build
// and sign a transaction, see what its size is, and then update the fee,
// rebuild the transaction, until the fee is set to the correct amount.
let fee_per_byte_nat = Nat64.toNat(fee_per_byte);
Debug.print("Building transaction...");
var total_fee : Nat = 0;
loop {
let transaction =
Utils.get_ok_except(Bitcoin.buildTransaction(2, own_utxos, [(#p2pkh dst_address, amount)], #p2pkh own_address, Nat64.fromNat(total_fee)), "Error building transaction.");
// Sign the transaction. In this case, we only care about the size
// of the signed transaction, so we use a mock signer here for efficiency.
let signed_transaction_bytes = await sign_transaction(
own_public_key,
own_address,
transaction,
"", // mock key name
[], // mock derivation path
mock_signer,
An outer function is taking dst_address
and is assuming it is p2pkh when passing it to an inner function. Unfortunately, the inner function only accepts the p2pkh type:
Not sure how necessary that restriction is. There is a whole file for bech32 in that repo:
import Text "mo:base/Text";
import Array "mo:base/Array";
import Iter "mo:base/Iter";
import Nat8 "mo:base/Nat8";
import Nat "mo:base/Nat";
import Nat32 "mo:base/Nat32";
import Blob "mo:base/Blob";
import Buffer "mo:base/Buffer";
import Result "mo:base/Result";
import Char "mo:base/Char";
module {
public type Encoding = {
#BECH32; #BECH32M;
};
// A decoded result contains Encoding type, human-readable part (HRP), and Data.
public type DecodeResult = (Encoding, Text, [Nat8]);
let CHAR_a : Nat8 = 0x61;
This file has been truncated. show original