Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Motoko Bitcoin example #606

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/motoko-basic-bitcoin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
dfx start --background
pushd motoko/basic_bitcoin
dfx deploy basic_bitcoin --argument '(variant { Regtest })'
dfx deploy basic_bitcoin --argument '(variant { regtest })'
popd
rust-basic-bitcoin-linux:
runs-on: ubuntu-20.04
Expand All @@ -39,5 +39,5 @@ jobs:
run: |
dfx start --background
pushd motoko/basic_bitcoin
dfx deploy basic_bitcoin --argument '(variant { Regtest })'
dfx deploy basic_bitcoin --argument '(variant { regtest })'
popd
14 changes: 13 additions & 1 deletion motoko/basic_bitcoin/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@
}
},
"defaults": {
"bitcoin": {
"enabled": true,
"nodes": [
"127.0.0.1:18444"
],
"log_level": "info"
},
"build": {
"packtool": "",
"args": ""
}
},
"networks": {
"local": {
"bind": "127.0.0.1:4943"
}
}
}
}
6 changes: 3 additions & 3 deletions motoko/basic_bitcoin/src/basic_bitcoin/basic_bitcoin.did
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ type bitcoin_address = text;
type block_hash = blob;

type network = variant {
Regtest;
Testnet;
Mainnet;
regtest;
testnet;
mainnet;
};

type outpoint = record {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public func build_transaction(
let public_key = public_key_bytes_to_public_key(public_key_bytes);

// Compute the P2PKH address from our public key.
P2pkh.deriveAddress(network, Publickey.toSec1(public_key, true))
P2pkh.deriveAddress(Types.network_to_network_camel_case(network), Publickey.toSec1(public_key, true))
};

// A mock for rubber-stamping ECDSA signatures.
Expand Down
8 changes: 4 additions & 4 deletions motoko/basic_bitcoin/src/basic_bitcoin/src/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ actor class BasicBitcoin(_network : Types.Network) {

// The Bitcoin network to connect to.
//
// When developing locally this should be `Regtest`.
// When deploying to the IC this should be `Testnet`.
// `Mainnet` is currently unsupported.
// When developing locally this should be `regtest`.
// When deploying to the IC this should be `testnet`.
// `mainnet` is currently unsupported.
stable let NETWORK : Network = _network;

// The derivation path to use for ECDSA secp256k1.
Expand All @@ -26,7 +26,7 @@ actor class BasicBitcoin(_network : Types.Network) {
// The ECDSA key name.
let KEY_NAME : Text = switch NETWORK {
// For local development, we use a special test key with dfx.
case (#Regtest) "dfx_test_key";
case (#regtest) "dfx_test_key";
// On the IC we're using a test ECDSA key.
case _ "test_key_1"
};
Expand Down
24 changes: 23 additions & 1 deletion motoko/basic_bitcoin/src/basic_bitcoin/src/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,33 @@ module Types {

/// The type of Bitcoin network the dapp will be interacting with.
public type Network = {
#mainnet;
#testnet;
#regtest;
};

/// The type of Bitcoin network as defined by the Bitcoin Motoko library
/// (Note the difference in casing compared to `Network`)
public type NetworkCamelCase = {
#Mainnet;
#Testnet;
#Regtest;
};

public func network_to_network_camel_case(network: Network) : NetworkCamelCase {
switch (network) {
case (#regtest) {
#Regtest
};
case (#testnet) {
#Testnet
};
case (#mainnet) {
#Mainnet
};
}
};

/// A reference to a transaction output.
public type OutPoint = {
txid : Blob;
Expand Down Expand Up @@ -102,4 +124,4 @@ module Types {
transaction : [Nat8];
network : Network;
};
}
}
Loading