From 9b6bbb25f92bf2dc2d2c57786419fbdc379e7506 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Fri, 20 Oct 2023 16:25:27 -0500 Subject: [PATCH] feat: script for creating test domain data Fixes #54 --- scripts/create-test-data/README.md | 17 ++++++ scripts/create-test-data/create-test-data | 20 +++++++ scripts/create-test-data/main.ts | 70 +++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 scripts/create-test-data/README.md create mode 100755 scripts/create-test-data/create-test-data create mode 100644 scripts/create-test-data/main.ts diff --git a/scripts/create-test-data/README.md b/scripts/create-test-data/README.md new file mode 100644 index 0000000..baefd8a --- /dev/null +++ b/scripts/create-test-data/README.md @@ -0,0 +1,17 @@ +# create-test-data + +This script is uses to generate transactions containing test domain data for use with cdnsd + +To run it, you need to provide a few things: + +* a Maestro API key for preprod +* the domain to create an entry for +* the nameservers for the domain +* the source address for the TX to generate (you must be able to sign TXes for this address) +* the destination address for the TX to generate (this will be consumed by cdnsd) + +``` +$ MAESTRO_API_KEY=xxxxxx ./create-test-data -D foo.cardano -n 1.2.3.4 -n 2.3.4.5 -s addr_test1qrldjljcfh6e8cg4z5uu6l7s7dccx5kyk0vppny2yldxqd0uts9m9rn7fhqnm3eluw8m8ytuupw4sjlrcnp2jlc2g8qsn9p8p0 -d addr_test1vpzje979n2swggeu24ehty8nka2fh7zu3jykfrazfwfff4c2yvx4d +``` + +Once the script generates the transaction, you'll need to import it into a wallet such as Eternl to sign and submit it. diff --git a/scripts/create-test-data/create-test-data b/scripts/create-test-data/create-test-data new file mode 100755 index 0000000..485c946 --- /dev/null +++ b/scripts/create-test-data/create-test-data @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +_deno_image='denoland/deno:1.37.2' +_deno_flags=( + '--allow-net' + '--allow-read' + '--allow-env' +) + +_script_dir=$(cd $(dirname $0); pwd) + +docker run \ + -ti --rm \ + -v ${_script_dir}:/app \ + -v $(pwd):/work \ + -v ${HOME}/.deno:/deno-dir \ + -w /work \ + -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 new file mode 100644 index 0000000..a9ec117 --- /dev/null +++ b/scripts/create-test-data/main.ts @@ -0,0 +1,70 @@ +import { loadSync } from "https://deno.land/std@0.199.0/dotenv/mod.ts"; +import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts"; +import { + Constr, + Data, + fromText, + toHex, + Lucid, + Maestro, +} from "https://deno.land/x/lucid@0.10.7/mod.ts"; + +loadSync({ export: true, allowEmptyValues: true }); + +const generate = new Command() + .description("Generate an unsigned TX with the test domain data") + .env("MAESTRO_API_KEY=", "Maestro API key", { required: true }) + .option("-D, --domain ", "Domain to create test data for", { required: true }) + .option("-n, --nameserver ", "Nameserver for domain (can be specified multiple times)", { collect: true, required: 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, sourceAddress, destAddress }) => { + console.log(`Building transaction...`); + + const provider = new Maestro({ + network: "Preprod", + apiKey: maestroApiKey, // Get yours by visiting https://docs.gomaestro.org/docs/Getting-started/Sign-up-login. + turboSubmit: false + }); + const lucid = await Lucid.new(provider, "Preprod"); + + lucid.selectWalletFrom({ address: sourceAddress }); + + // TODO: update datum format + const outDatum = new Constr(0, [ + fromText(domain), + new Constr(0, nameserver.map(nameserver => fromText(nameserver))), + ]); + + const outDatumEncoded = Data.to(outDatum); + + try { + const txOut = await lucid + .newTx() + .payToAddressWithData( + destAddress, + { inline: outDatumEncoded }, + { lovelace: 2_000_000 }, + ) + // 10 minutes + .validTo(Date.now() + 600_000) + .complete(); + + const txJsonObj = { + "type": "Tx BabbageEra", + "description": "unsigned", + "cborHex": txOut.toString(), + }; + console.log(`\nTX (unsigned):\n`); + console.log(JSON.stringify(txJsonObj)); + console.log(`\nNOTE: you must import this transaction into a wallet such as Eternl to sign and submit it`); + } catch (e) { + console.log(e); + } + }); + +await new Command() + .name("create-test-data") + .description("Create test domain data for cdnsd") + .command("generate", generate) + .parse(Deno.args);