diff --git a/src/Bitcoin.mo b/src/Bitcoin.mo new file mode 100644 index 00000000..0e444bc4 --- /dev/null +++ b/src/Bitcoin.mo @@ -0,0 +1,73 @@ +// This is a generated Motoko binding. +// Please use `import service "ic:canister_id"` instead to call canisters on the IC if possible. + +module { + public type address = Text; + public type block_hash = Blob; + public type config = { + api_access : flag; + blocks_source : Principal; + fees : fees; + watchdog_canister : ?Principal; + network : network; + stability_threshold : Nat; + syncing : flag; + disable_api_if_not_fully_synced : flag; + }; + public type fees = { + get_current_fee_percentiles : Nat; + get_utxos_maximum : Nat; + get_current_fee_percentiles_maximum : Nat; + send_transaction_per_byte : Nat; + get_balance : Nat; + get_utxos_cycles_per_ten_instructions : Nat; + get_utxos_base : Nat; + get_balance_maximum : Nat; + send_transaction_base : Nat; + }; + public type flag = { #disabled; #enabled }; + public type get_balance_request = { + network : network; + address : address; + min_confirmations : ?Nat32; + }; + public type get_current_fee_percentiles_request = { network : network }; + public type get_utxos_request = { + network : network; + filter : ?{ #page : Blob; #min_confirmations : Nat32 }; + address : address; + }; + public type get_utxos_response = { + next_page : ?Blob; + tip_height : Nat32; + tip_block_hash : block_hash; + utxos : [utxo]; + }; + public type millisatoshi_per_byte = Nat64; + public type network = { #mainnet; #regtest; #testnet }; + public type outpoint = { txid : Blob; vout : Nat32 }; + public type satoshi = Nat64; + public type send_transaction_request = { + transaction : Blob; + network : network; + }; + public type set_config_request = { + api_access : ?flag; + fees : ?fees; + watchdog_canister : ??Principal; + stability_threshold : ?Nat; + syncing : ?flag; + disable_api_if_not_fully_synced : ?flag; + }; + public type utxo = { height : Nat32; value : satoshi; outpoint : outpoint }; + public type Self = config -> async actor { + bitcoin_get_balance : shared get_balance_request -> async satoshi; + bitcoin_get_current_fee_percentiles : shared get_current_fee_percentiles_request -> async [ + millisatoshi_per_byte + ]; + bitcoin_get_utxos : shared get_utxos_request -> async get_utxos_response; + bitcoin_send_transaction : shared send_transaction_request -> async (); + get_config : shared query () -> async config; + set_config : shared set_config_request -> async (); + } +} diff --git a/src/CyclesLedger.mo b/src/CyclesLedger.mo new file mode 100644 index 00000000..cb6c85ea --- /dev/null +++ b/src/CyclesLedger.mo @@ -0,0 +1,78 @@ +module { + public type Account = { owner : Principal; subaccount : ?Subaccount }; + public type BlockIndex = Nat; + public type Duration = Nat64; + public type RejectionCode = { + #NoError; + #CanisterError; + #SysTransient; + #DestinationInvalid; + #Unknown; + #SysFatal; + #CanisterReject + }; + public type SendArg = { + to : Principal; + fee : ?Nat; + memo : ?Blob; + from_subaccount : ?Subaccount; + created_at_time : ?Timestamp; + amount : Nat + }; + public type SendError = { fee_block : BlockIndex; reason : SendErrorReason }; + public type SendErrorReason = { + #GenericError : { message : Text; error_code : Nat }; + #TemporarilyUnavailable; + #FailedToSend : { rejection_code : RejectionCode; rejection_reason : Text }; + #Duplicate : { duplicate_of : BlockIndex }; + #BadFee : { expected_fee : Nat }; + #InvalidReceiver : { receiver : Principal }; + #CreatedInFuture : { ledger_time : Timestamp }; + #TooOld; + #InsufficientFunds : { balance : Nat } + }; + public type Subaccount = Blob; + public type Timestamp = Nat64; + public type TransferArgs = { + to : Account; + fee : ?Nat; + memo : ?Blob; + from_subaccount : ?Subaccount; + created_at_time : ?Timestamp; + amount : Nat + }; + public type TransferError = { + #GenericError : { message : Text; error_code : Nat }; + #TemporarilyUnavailable; + #BadBurn : { min_burn_amount : Nat }; + #Duplicate : { duplicate_of : BlockIndex }; + #BadFee : { expected_fee : Nat }; + #CreatedInFuture : { ledger_time : Timestamp }; + #TooOld; + #InsufficientFunds : { balance : Nat } + }; + public type Value = { #Int : Int; #Nat : Nat; #Blob : Blob; #Text : Text }; + public type Self = actor { + deposit : shared { to : Account; memo : ?Blob } -> async { + balance : Nat; + txid : BlockIndex + }; + icrc1_balance_of : shared query Account -> async Nat; + icrc1_decimals : shared query () -> async Nat8; + icrc1_fee : shared query () -> async Nat; + icrc1_metadata : shared query () -> async [(Text, Value)]; + icrc1_minting_account : shared query () -> async ?Account; + icrc1_name : shared query () -> async Text; + icrc1_supported_standards : shared query () -> async [{ + url : Text; + name : Text + }]; + icrc1_symbol : shared query () -> async Text; + icrc1_total_supply : shared query () -> async Nat; + icrc1_transfer : shared TransferArgs -> async { + #Ok : BlockIndex; + #Err : TransferError + }; + send : shared SendArg -> async { #Ok : BlockIndex; #Err : SendError } + } +} diff --git a/src/Management.mo b/src/Management.mo new file mode 100644 index 00000000..36eb9886 --- /dev/null +++ b/src/Management.mo @@ -0,0 +1,131 @@ +module { + public type bitcoin_address = Text; + public type bitcoin_network = { #mainnet; #testnet }; + public type block_hash = [Nat8]; + public type canister_id = Principal; + public type canister_settings = { + freezing_threshold : ?Nat; + controllers : ?[Principal]; + memory_allocation : ?Nat; + compute_allocation : ?Nat + }; + public type definite_canister_settings = { + freezing_threshold : Nat; + controllers : [Principal]; + memory_allocation : Nat; + compute_allocation : Nat + }; + public type ecdsa_curve = { #secp256k1 }; + public type get_balance_request = { + network : bitcoin_network; + address : bitcoin_address; + min_confirmations : ?Nat32 + }; + public type get_current_fee_percentiles_request = { + network : bitcoin_network + }; + public type get_utxos_request = { + network : bitcoin_network; + filter : ?{ #page : [Nat8]; #min_confirmations : Nat32 }; + address : bitcoin_address + }; + public type get_utxos_response = { + next_page : ?[Nat8]; + tip_height : Nat32; + tip_block_hash : block_hash; + utxos : [utxo] + }; + public type http_header = { value : Text; name : Text }; + public type http_response = { + status : Nat; + body : [Nat8]; + headers : [http_header] + }; + public type millisatoshi_per_byte = Nat64; + public type outpoint = { txid : [Nat8]; vout : Nat32 }; + public type satoshi = Nat64; + + public type send_transaction_request = { + transaction : [Nat8]; + network : bitcoin_network + }; + + public type user_id = Principal; + + public type utxo = { height : Nat32; value : satoshi; outpoint : outpoint }; + + public type wasm_module = [Nat8]; + + public type Self = actor { + bitcoin_get_balance : shared get_balance_request -> async satoshi; + bitcoin_get_current_fee_percentiles : shared get_current_fee_percentiles_request -> async [ + millisatoshi_per_byte + ]; + bitcoin_get_utxos : shared get_utxos_request -> async get_utxos_response; + bitcoin_send_transaction : shared send_transaction_request -> async (); + + canister_status : shared { canister_id : canister_id } -> async { + status : { #stopped; #stopping; #running }; + memory_size : Nat; + cycles : Nat; + settings : definite_canister_settings; + idle_cycles_burned_per_day : Nat; + module_hash : ?[Nat8] + }; + create_canister : shared { settings : ?canister_settings } -> async { + canister_id : canister_id + }; + + delete_canister : shared { canister_id : canister_id } -> async (); + deposit_cycles : shared { canister_id : canister_id } -> async (); + + ecdsa_public_key : shared { + key_id : { name : Text; curve : ecdsa_curve }; + canister_id : ?canister_id; + derivation_path : [[Nat8]] + } -> async { public_key : [Nat8]; chain_code : [Nat8] }; + + http_request : shared { + url : Text; + method : { #get; #head; #post }; + max_response_bytes : ?Nat64; + body : ?[Nat8]; + transform : ?{ + function : shared query { + context : [Nat8]; + response : http_response + } -> async http_response; + context : [Nat8] + }; + headers : [http_header] + } -> async http_response; + install_code : shared { + arg : [Nat8]; + wasm_module : wasm_module; + mode : { #reinstall; #upgrade; #install }; + canister_id : canister_id + } -> async (); + provisional_create_canister_with_cycles : shared { + settings : ?canister_settings; + specified_id : ?canister_id; + amount : ?Nat + } -> async { canister_id : canister_id }; + provisional_top_up_canister : shared { + canister_id : canister_id; + amount : Nat + } -> async (); + raw_rand : shared () -> async [Nat8]; + sign_with_ecdsa : shared { + key_id : { name : Text; curve : ecdsa_curve }; + derivation_path : [[Nat8]]; + message_hash : [Nat8] + } -> async { signature : [Nat8] }; + start_canister : shared { canister_id : canister_id } -> async (); + stop_canister : shared { canister_id : canister_id } -> async (); + uninstall_code : shared { canister_id : canister_id } -> async (); + update_settings : shared { + canister_id : Principal; + settings : canister_settings + } -> async () + } +}