Skip to content

Commit 53dcc35

Browse files
authored
Merge pull request #75 from blinklabs-io/feat/datum-format-update
feat: update test data script for new datum format
2 parents ec0c4ef + 4ca568f commit 53dcc35

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

scripts/create-test-data/main.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const generate = new Command()
1515
.description("Generate an unsigned TX with the test domain data")
1616
.env("MAESTRO_API_KEY=<value:string>", "Maestro API key", { required: true })
1717
.option("-D, --domain <domain>", "Domain to create test data for", { required: true })
18-
.option("-n, --nameserver <nameserver>", "Nameserver for domain, specified as a <hostname,ipaddress> pair (can be specified multiple times)", { collect: true, required: true })
18+
.option("-r, --record <record>", "Record for domain, specified as: <name>[,<ttl>],<type>,<value> (can be specified multiple times)", { collect: true, required: true })
1919
.option("-s, --source-address <address>", "Source wallet address to send from (you must be able to sign transactions for this)", { required: true })
2020
.option("-d, --dest-address <address>", "Destination wallet address to send to (this will be read by cdnsd)", { required: true })
21-
.action(async ({ maestroApiKey, domain, nameserver, sourceAddress, destAddress }) => {
21+
.action(async ({ maestroApiKey, domain, record, sourceAddress, destAddress }) => {
2222
console.log(`Building transaction...`);
2323

2424
const provider = new Maestro({
@@ -30,19 +30,37 @@ const generate = new Command()
3030

3131
lucid.selectWalletFrom({ address: sourceAddress });
3232

33-
// TODO: update datum format
34-
const outDatum = new Constr(0, [
33+
let outDatumRecords = []
34+
record.forEach((tmpRecord) => {
35+
const recordParts = tmpRecord.split(",")
36+
if (recordParts.length == 3) {
37+
outDatumRecords.push(new Constr(
38+
1,
39+
[
40+
fromText(recordParts[0]),
41+
fromText(recordParts[1]),
42+
fromText(recordParts[2]),
43+
],
44+
))
45+
} else if (recordParts.length == 4) {
46+
outDatumRecords.push(new Constr(
47+
1,
48+
[
49+
fromText(recordParts[0]),
50+
BigInt(parseInt(recordParts[1])),
51+
fromText(recordParts[2]),
52+
fromText(recordParts[3]),
53+
],
54+
))
55+
} else {
56+
console.log(`Invalid record: ${tmpRecord}`)
57+
Deno.exit(1)
58+
}
59+
})
60+
61+
const outDatum = new Constr(1, [
3562
fromText(domain),
36-
// [ Constr(0, ...), Constr(0, ...), ... ]
37-
nameserver.map(
38-
nameserver => new Constr(
39-
0,
40-
// Split nameserver hostname and IP address and convert both to bytestrings
41-
nameserver.split(",").map(
42-
nameserver => fromText(nameserver),
43-
),
44-
),
45-
),
63+
outDatumRecords,
4664
]);
4765

4866
const outDatumEncoded = Data.to(outDatum);

0 commit comments

Comments
 (0)