-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from blinklabs-io/feat/test-data-script
feat: script for creating test domain data
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |