From 0bc6dc8588c62d3e8bbce37b1356008cdb4fcfe4 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 20 Dec 2023 16:06:50 +0100 Subject: [PATCH] bump stacks-core next branch, include tx-broadcasting script --- Dockerfile.tx-broadcaster | 9 +++++++ docker-compose.yml | 16 +++++++++-- stacking/tx-broadcaster.js | 54 ++++++++++++++++++++++++++++++++++++++ stacks-krypton-miner.toml | 10 +++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.tx-broadcaster create mode 100644 stacking/tx-broadcaster.js diff --git a/Dockerfile.tx-broadcaster b/Dockerfile.tx-broadcaster new file mode 100644 index 0000000..391d9cd --- /dev/null +++ b/Dockerfile.tx-broadcaster @@ -0,0 +1,9 @@ +FROM node:18-bookworm as builder + +RUN apt-get update && apt-get install -y curl gettext-base jq + +WORKDIR /root +COPY ./stacking/tx-broadcaster.js ./stacking/package.json /root/ +RUN npm i + +CMD ["node", "/root/tx-broadcaster.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 845c217..f5670e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 8cffc3892f6451fdff525952a025f77482a8f728 + - &STACKS_BLOCKCHAIN_COMMIT 2789b184ef301734f0af2132fac4b303ef0f9a7c - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 @@ -141,7 +141,6 @@ services: bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo exec stacks-node start --config=config.toml - stacker: networks: - stacks @@ -155,6 +154,19 @@ services: depends_on: - stacks-node + tx-broadcaster: + networks: + - stacks + build: + context: . + dockerfile: Dockerfile.tx-broadcaster + environment: + STACKS_CORE_RPC_HOST: stacks-node + STACKS_CORE_RPC_PORT: 20443 + ACCOUNT_KEYS: 0d2f965b472a82efd5a96e6513c8b9f7edc725d5c96c7d35d6c722cedeb80d1b01,975b251dd7809469ef0c26ec3917971b75c51cd73a022024df4bf3b232cc2dc001,c71700b07d520a8c9731e4d0f095aa6efb91e16e25fb27ce2b72e7b698f8127a01 + depends_on: + - stacks-node + postgres: networks: - stacks diff --git a/stacking/tx-broadcaster.js b/stacking/tx-broadcaster.js new file mode 100644 index 0000000..0fbcbf8 --- /dev/null +++ b/stacking/tx-broadcaster.js @@ -0,0 +1,54 @@ +const { StacksTestnet } = require('@stacks/network'); +const { TransactionVersion, getAddressFromPrivateKey, getNonce, makeSTXTokenTransfer, broadcastTransaction } = require('@stacks/transactions'); + +const broadcastInterval = process.env.BROADCAST_INTERVAL ?? 2; +const postTxWait = process.env.POST_TX_WAIT ?? 2; +const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; +const network = new StacksTestnet({ url }); + +const accounts = process.env.ACCOUNT_KEYS.split(',').map(privKey => ({ + privKey, + stxAddress: getAddressFromPrivateKey(privKey, TransactionVersion.Testnet), +})); + +async function run() { + const accountNonces = await Promise.all(accounts.map(async (account) => { + const nonce = await getNonce(account.stxAddress, network); + return { ...account, nonce }; + })); + + // Send from account with lowest nonce + accountNonces.sort((a, b) => Number(a.nonce) - Number(b.nonce)); + const sender = accountNonces[0]; + const recipient = accountNonces[1]; + + console.log(`Sending stx-transfer from ${sender.stxAddress} (nonce=${sender.nonce}) to ${recipient.stxAddress}`); + + const tx = await makeSTXTokenTransfer({ + recipient: recipient.stxAddress, + amount: 1000, + senderKey: sender.privKey, + network, + nonce: sender.nonce, + fee: 300, + }); + + const broadcastResult = await broadcastTransaction(tx, network); + if (broadcastResult.error) { + console.error('Error broadcasting stx-transfer', broadcastResult); + } else { + console.log(`Broadcast stx-transfer tx=${broadcastResult.txid}`); + } + + await new Promise(resolve => setTimeout(resolve, postTxWait * 1000)); +} + +async function loop() { + try { + await run(); + } catch (e) { + console.error('Error submitting stx-transfer tx:', e); + } + setTimeout(loop, broadcastInterval * 1000); +} +loop(); diff --git a/stacks-krypton-miner.toml b/stacks-krypton-miner.toml index 662ee1f..65bfac4 100644 --- a/stacks-krypton-miner.toml +++ b/stacks-krypton-miner.toml @@ -107,6 +107,16 @@ address = "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR" amount = 10000000000000000 # secretKey = "c71700b07d520a8c9731e4d0f095aa6efb91e16e25fb27ce2b72e7b698f8127a01" +[[ustx_balance]] +address = "ST2PGGD0ZXAWEMY4EZ025RD1X47EEVH287SQKA8BC" +amount = 10000000000000000 +# secretKey = "975b251dd7809469ef0c26ec3917971b75c51cd73a022024df4bf3b232cc2dc001" + +[[ustx_balance]] +address = "ST29V10QEA7BRZBTWRFC4M70NJ4J6RJB5P1C6EE84" +amount = 10000000000000000 +# secretKey = "0d2f965b472a82efd5a96e6513c8b9f7edc725d5c96c7d35d6c722cedeb80d1b01" + [[ustx_balance]] address = "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP" amount = 10000000000000000