From f5d26600c6ea4701488feb6e2cb9d504a5f44062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Haf?= Date: Sat, 22 Mar 2025 10:44:23 +0100 Subject: [PATCH 1/4] get address action --- Dockerfile | 1 + actions/getaddress.sh | 23 +++++++++++++++++++++++ manifest.yaml | 15 +++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 actions/getaddress.sh diff --git a/Dockerfile b/Dockerfile index 9f3014e..2758604 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,6 +82,7 @@ ENV PATH=${BITCOIN_PREFIX}/bin:$PATH COPY --from=bitcoin-core /opt /opt COPY ./manager/target/${ARCH}-unknown-linux-musl/release/bitcoind-manager \ ./docker_entrypoint.sh \ + ./actions/getaddress.sh \ ./actions/reindex.sh \ ./actions/reindex_chainstate.sh \ ./actions/prioritise-transaction.sh \ diff --git a/actions/getaddress.sh b/actions/getaddress.sh new file mode 100644 index 0000000..4c0f170 --- /dev/null +++ b/actions/getaddress.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if ! bitcoin-cli listwalletdir | jq -e '.wallets[] | select(.name == "coin")' &> /dev/null; then + bitcoin-cli createwallet "coin" &> /dev/null +fi + +if ! bitcoin-cli getwalletinfo &> /dev/null; then + bitcoin-cli loadwallet coin &> /dev/null +fi + +ADDRESS=$(bitcoin-cli getnewaddress "" "bech32") + +result=" { + \"version\": \"0\", + \"message\": \"$ADDRESS\", + \"value\": null, + \"copyable\": true, + \"qr\": false +}" + +echo $result \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml index 203a5b2..0d9a6c9 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -225,6 +225,21 @@ actions: range: "[-1000000,1000000]" default: 0 nullable: true + getaddress: + name: "Get new address" + description: "Get a new Bitcoin address." + allowed-statuses: + - running + implementation: + type: docker + image: main + system: false + entrypoint: getaddress.sh + args: [] + io-format: json + mounts: + main: /root/.bitcoin + inject: true migrations: from: "*": From f91aa51b5b5d69dbef27c6b202be934d2b71c9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Haf?= Date: Mon, 24 Mar 2025 14:08:05 +0100 Subject: [PATCH 2/4] get wallet balance action --- Dockerfile | 1 + actions/getbalance.sh | 27 +++++++++++++++++++++++++++ manifest.yaml | 15 +++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 actions/getbalance.sh diff --git a/Dockerfile b/Dockerfile index 2758604..34b1b88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,6 +83,7 @@ COPY --from=bitcoin-core /opt /opt COPY ./manager/target/${ARCH}-unknown-linux-musl/release/bitcoind-manager \ ./docker_entrypoint.sh \ ./actions/getaddress.sh \ + ./actions/getbalance.sh \ ./actions/reindex.sh \ ./actions/reindex_chainstate.sh \ ./actions/prioritise-transaction.sh \ diff --git a/actions/getbalance.sh b/actions/getbalance.sh new file mode 100644 index 0000000..2a7c5b3 --- /dev/null +++ b/actions/getbalance.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -e + +if ! bitcoin-cli listwalletdir | jq -e '.wallets[] | select(.name == "coin")' &> /dev/null; then + bitcoin-cli createwallet "coin" &> /dev/null +fi + +if ! bitcoin-cli getwalletinfo &> /dev/null; then + bitcoin-cli loadwallet coin &> /dev/null +fi + +TRUSTED=$(bitcoin-cli getbalances | jq -r '.mine.trusted') +UNTRUSTED=$(bitcoin-cli getbalances | jq -r '.mine.untrusted_pending') +IMMATURE=$(bitcoin-cli getbalances | jq -r '.mine.immature') + +result=" { + \"version\": \"0\", + \"message\": \"Your wallet balance: $TRUSTED BTC. / + Non confirmed balance: $UNTRUSTED BTC. / + Immanture balance from mining: $IMMATURE BTC.\", + \"value\": null, + \"copyable\": true, + \"qr\": false +}" + +echo $result \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml index 0d9a6c9..5ab832f 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -240,6 +240,21 @@ actions: mounts: main: /root/.bitcoin inject: true + getbalance: + name: "Get wallet balance" + description: "Get wallet balance." + allowed-statuses: + - running + implementation: + type: docker + image: main + system: false + entrypoint: getbalance.sh + args: [] + io-format: json + mounts: + main: /root/.bitcoin + inject: true migrations: from: "*": From 2e7b73f8c79e87bfd860e99df1d3afc1f4c3ac01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Haf?= Date: Tue, 25 Mar 2025 09:55:09 +0100 Subject: [PATCH 3/4] send coin action --- Dockerfile | 1 + actions/sendcoin.sh | 36 ++++++++++++++++++++++++++++++++++++ manifest.yaml | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 actions/sendcoin.sh diff --git a/Dockerfile b/Dockerfile index 34b1b88..5a43355 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,6 +85,7 @@ COPY ./manager/target/${ARCH}-unknown-linux-musl/release/bitcoind-manager \ ./actions/getaddress.sh \ ./actions/getbalance.sh \ ./actions/reindex.sh \ + ./actions/sendcoin.sh \ ./actions/reindex_chainstate.sh \ ./actions/prioritise-transaction.sh \ ./check-rpc.sh \ diff --git a/actions/sendcoin.sh b/actions/sendcoin.sh new file mode 100644 index 0000000..d314353 --- /dev/null +++ b/actions/sendcoin.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -e + +if ! bitcoin-cli listwalletdir | jq -e '.wallets[] | select(.name == "coin")' &> /dev/null; then + bitcoin-cli createwallet "coin" &> /dev/null +fi + +if ! bitcoin-cli getwalletinfo &> /dev/null; then + bitcoin-cli loadwallet coin &> /dev/null +fi + +cat > input.json +ADDRESS=$(jq -r '.["address"]' input.json) + +AMOUNT=$(jq -r '.["amount"]' input.json) +if [ $AMOUNT = "null" ]; then + AMOUNT="0" +fi + +FEE=$(jq -r '.["fee"]' input.json) +if [ $FEE = "null" ]; then + FEE="0" +fi + +TXID=$(bitcoin-cli -named sendtoaddress address=$ADDRESS amount=$AMOUNT fee_rate=$FEE) + +result=" { + \"version\": \"0\", + \"message\": \"txid: $TXID\", + \"value\": null, + \"copyable\": true, + \"qr\": false +}" + +echo $result \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml index 5ab832f..4fa64db 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -255,6 +255,44 @@ actions: mounts: main: /root/.bitcoin inject: true + sendcoin: + name: "Send bitcoin" + description: "Send bitcoin to an address." + allowed-statuses: + - running + implementation: + type: docker + image: main + system: false + entrypoint: sendcoin.sh + args: [] + io-format: json + mounts: + main: /root/.bitcoin + inject: true + input-spec: + address: + type: string + name: Address + description: "The bitcoin address you want to send your bitcoins." + placeholder: "" + nullable: false + amount: + type: number + name: Amount (BTC) + description: "The amount of bitcoin you want to send to the address." + integral: false + range: "[0,21000000]" + default: 0 + nullable: false + fee: + type: number + name: Fee (sat/vbytes) + description: "The amount of fee you want to pay for this transaction (in sat per vbytes)" + integral: false + range: "[0,1000000]" + default: 0 + nullable: false migrations: from: "*": From 5dc838cb86cacf071ee9b722ed44ca8a614c35de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Haf?= Date: Wed, 26 Mar 2025 10:50:10 +0100 Subject: [PATCH 4/4] add sendall action --- Dockerfile | 1 + actions/sendall.sh | 31 +++++++++++++++++++++++++++++++ manifest.yaml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 actions/sendall.sh diff --git a/Dockerfile b/Dockerfile index 5a43355..b637410 100644 --- a/Dockerfile +++ b/Dockerfile @@ -86,6 +86,7 @@ COPY ./manager/target/${ARCH}-unknown-linux-musl/release/bitcoind-manager \ ./actions/getbalance.sh \ ./actions/reindex.sh \ ./actions/sendcoin.sh \ + ./actions/sendall.sh \ ./actions/reindex_chainstate.sh \ ./actions/prioritise-transaction.sh \ ./check-rpc.sh \ diff --git a/actions/sendall.sh b/actions/sendall.sh new file mode 100644 index 0000000..c7b320b --- /dev/null +++ b/actions/sendall.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +set -e + +if ! bitcoin-cli listwalletdir | jq -e '.wallets[] | select(.name == "coin")' &> /dev/null; then + bitcoin-cli createwallet "coin" &> /dev/null +fi + +if ! bitcoin-cli getwalletinfo &> /dev/null; then + bitcoin-cli loadwallet coin &> /dev/null +fi + +cat > input.json +ADDRESS=$(jq -r '.["address"]' input.json) + +FEE=$(jq -r '.["fee"]' input.json) +if [ $FEE = "null" ]; then + FEE="0" +fi + +TXID=$(bitcoin-cli -named sendall recipients="[\"$ADDRESS\"]" fee_rate=$FEE | jq -r '.txid') + +result=" { + \"version\": \"0\", + \"message\": \"txid: $TXID\", + \"value\": null, + \"copyable\": true, + \"qr\": false +}" + +echo $result \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml index 4fa64db..b6c2da4 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -293,6 +293,36 @@ actions: range: "[0,1000000]" default: 0 nullable: false + sendall: + name: "Send all bitcoin" + description: "Send ALL bitcoin in the wallet." + allowed-statuses: + - running + implementation: + type: docker + image: main + system: false + entrypoint: sendall.sh + args: [] + io-format: json + mounts: + main: /root/.bitcoin + inject: true + input-spec: + address: + type: string + name: Address + description: "The bitcoin address you want to send your bitcoins." + placeholder: "" + nullable: false + fee: + type: number + name: Fee (sat/vbytes) + description: "The amount of fee you want to pay for this transaction (in sat per vbytes)" + integral: false + range: "[0,1000000]" + default: 0 + nullable: false migrations: from: "*":