Closed lastmjs closed 2 years ago
Quick progress update.
I've created all the necessary TS types in https://github.com/demergent-labs/azle/pull/627. Once that's merged in you should no longer need to declare your own types. You can just import the management canister and start calling methods on it directly.
Example canister:
import { CanisterResult, Update, Variant } from 'azle';
import {
BitcoinNetwork,
ManagementCanister,
Satoshi
} from 'azle/canisters/management';
export type ExecuteGetBalanceResult = Variant<{
ok: Satoshi;
err: string;
}>;
export function* get_balance(address: string): Update<ExecuteGetBalanceResult> {
const BITCOIN_API_CYCLE_COST = 100_000_000n;
const canister_result: CanisterResult<Satoshi> =
yield ManagementCanister.bitcoin_get_balance({
address,
min_confirmations: null,
network: BitcoinNetwork.Regtest
}).with_cycles(BITCOIN_API_CYCLE_COST);
return canister_result;
}
I'm still working on creating a fully functioning example. I have one mostly working on the 565_bitcoin branch.
Where I'm currently hitting snags:
bitcoin-cli
. My current hypothesis is there must be something wrong about how I'm creating the address. I'm using P2WPKH addresses which should be supported, but something is off.bitcoind
already installed and available on your $PATH
. I'm working to get the test script to download and spin up the daemon as preparation steps, but am having difficulty getting the spawned child process to terminate correctly, leaving a ghost daemon process running.Made good progress today. The test suite is almost complete. I've got it downloading and running the bitcoin daemon inline. The test is getting hung up when mining blocks for some reason though. I make a call out to the bitcoin-cli and it never returns. So figuring that out is my next step.
But we've discovered the reason behind why the canister was always returning a balance of 0. The replica takes a little longer to pick up the state changes so we'll just have to add a delay in and then the balances should show up.
bitcoin_get_utxos
bitcoin_get_balance
bitcoin_send_transactions
bitcoin_get_current_fee_percentiles
Resources: