Skip to content

Commit

Permalink
bump stacks-core next branch, include tx-broadcasting script
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Dec 20, 2023
1 parent 658bb90 commit 0bc6dc8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Dockerfile.tx-broadcaster
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 14 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -141,7 +141,6 @@ services:
bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo
exec stacks-node start --config=config.toml
stacker:
networks:
- stacks
Expand All @@ -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
Expand Down
54 changes: 54 additions & 0 deletions stacking/tx-broadcaster.js
Original file line number Diff line number Diff line change
@@ -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();
10 changes: 10 additions & 0 deletions stacks-krypton-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bc6dc8

Please sign in to comment.