Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: script for creating test domain data #55

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions scripts/create-test-data/README.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions scripts/create-test-data/create-test-data
Original file line number Diff line number Diff line change
@@ -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 "$@"
70 changes: 70 additions & 0 deletions scripts/create-test-data/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { loadSync } from "https://deno.land/[email protected]/dotenv/mod.ts";
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import {
Constr,
Data,
fromText,
toHex,
Lucid,
Maestro,
} from "https://deno.land/x/[email protected]/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=<value:string>", "Maestro API key", { required: true })
.option("-D, --domain <domain>", "Domain to create test data for", { required: true })
.option("-n, --nameserver <nameserver>", "Nameserver for domain (can be specified multiple times)", { collect: true, required: true })
.option("-s, --source-address <address>", "Source wallet address to send from (you must be able to sign transactions for this)", { required: true })
.option("-d, --dest-address <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);
Loading