From 8f6be809ebecc9d99b33411b9ec30959a740bb9c Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Wed, 22 Nov 2023 15:25:46 -0600 Subject: [PATCH] feat: output test data transaction to file --- scripts/create-test-data/create-test-data | 2 ++ scripts/create-test-data/main.ts | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/create-test-data/create-test-data b/scripts/create-test-data/create-test-data index 485c946..83fe9ab 100755 --- a/scripts/create-test-data/create-test-data +++ b/scripts/create-test-data/create-test-data @@ -4,6 +4,7 @@ _deno_image='denoland/deno:1.37.2' _deno_flags=( '--allow-net' '--allow-read' + '--allow-write' '--allow-env' ) @@ -15,6 +16,7 @@ docker run \ -v $(pwd):/work \ -v ${HOME}/.deno:/deno-dir \ -w /work \ + -u $(id -u) \ -e MAESTRO_API_KEY=${MAESTRO_API_KEY} \ "${_deno_image}" \ run "${_deno_flags[@]}" /app/main.ts generate "$@" diff --git a/scripts/create-test-data/main.ts b/scripts/create-test-data/main.ts index 70d76a4..56304bc 100644 --- a/scripts/create-test-data/main.ts +++ b/scripts/create-test-data/main.ts @@ -19,7 +19,8 @@ const generate = new Command() .option("-r, --record ", "Record for domain, specified as: [,],, (can be specified multiple times)", { collect: true }) .option("-s, --source-address
", "Source wallet address to send from (you must be able to sign transactions for this)", { required: true }) .option("-d, --dest-address
", "Destination wallet address to send to (this will be read by cdnsd)", { required: true }) - .action(async ({ maestroApiKey, domain, nameserver, record, sourceAddress, destAddress }) => { + .option("-o, --output ", "Output file for generated transaction") + .action(async ({ maestroApiKey, domain, nameserver, record, sourceAddress, destAddress, output }) => { // Merge --nameserver and --record values let records = [] for (var tmpNameserver of nameserver) { @@ -97,8 +98,14 @@ const generate = new Command() "description": "unsigned", "cborHex": txOut.toString(), }; - console.log(`\nTX (unsigned):\n`); - console.log(JSON.stringify(txJsonObj)); + const txJson = JSON.stringify(txJsonObj) + + if (output === undefined) { + output = `./tx-cdnsd-test-data-${domain}-${txOut.toHash()}.json` + } + Deno.writeTextFileSync(output, txJson) + + console.log(`\nWrote tranaction to output file: ${output}`) console.log(`\nNOTE: you must import this transaction into a wallet such as Eternl to sign and submit it`); } catch (e) { console.log(e);