@@ -14,23 +14,34 @@ loadSync({ export: true, allowEmptyValues: true });
14
14
const generate = new Command ( )
15
15
. description ( "Generate an unsigned TX with the test domain data" )
16
16
. env ( "MAESTRO_API_KEY=<value:string>" , "Maestro API key" , { required : true } )
17
- . option ( "-D, --domain <domain>" , "Domain to create test data for" , { required : true } )
18
- . option ( "-n, --nameserver <nameserver>" , "Nameserver for domain, specified as: <name>,<ipaddr> (can be specified multiple times)" , { collect : true , required : true } )
17
+ . option ( "-f, --data-file <file>" , "JSON file containing domain data" )
18
+ . option ( "-D, --domain <domain>" , "Domain to create test data for" ) //, { required: true })
19
+ . option ( "-n, --nameserver <nameserver>" , "Nameserver for domain, specified as: <name>,<ipaddr> (can be specified multiple times)" , { collect : true } ) //, required: true })
19
20
. option ( "-r, --record <record>" , "Record for domain, specified as: <name>[,<ttl>],<type>,<value> (can be specified multiple times)" , { collect : true } )
20
- . option ( "-s, --source-address <address>" , "Source wallet address to send from (you must be able to sign transactions for this)" , { required : true } )
21
- . option ( "-d, --dest-address <address>" , "Destination wallet address to send to (this will be read by cdnsd)" , { required : true } )
21
+ . option ( "-s, --source-address <address>" , "Source wallet address to send from (you must be able to sign transactions for this)" ) // , { required: true })
22
+ . option ( "-d, --dest-address <address>" , "Destination wallet address to send to (this will be read by cdnsd)" ) // , { required: true })
22
23
. option ( "-o, --output <file>" , "Output file for generated transaction" )
23
- . action ( async ( { maestroApiKey, domain, nameserver, record, sourceAddress, destAddress, output } ) => {
24
- // Merge --nameserver and --record values
25
- let records = [ ]
26
- for ( var tmpNameserver of nameserver ) {
27
- const tmpNameserverParts = tmpNameserver . split ( "," )
28
- // Nameservers for a domain need both a NS record on the domain and an A record for themselves
29
- records . push ( `${ domain } ,ns,${ tmpNameserverParts [ 0 ] } ` )
30
- records . push ( `${ tmpNameserverParts [ 0 ] } ,a,${ tmpNameserverParts [ 1 ] } ` )
31
- }
32
- for ( var tmpRecord in record ) {
33
- records . push ( tmpRecord )
24
+ . action ( async ( { maestroApiKey, dataFile, domain, nameserver, record, sourceAddress, destAddress, output } ) => {
25
+ let domains = [ ]
26
+ if ( dataFile === undefined ) {
27
+ // TODO: check for required params
28
+ let tmpDomain = {
29
+ origin : domain ,
30
+ records : [ ] ,
31
+ }
32
+ // Merge --nameserver and --record values
33
+ for ( var tmpNameserver of nameserver ) {
34
+ const tmpNameserverParts = tmpNameserver . split ( "," )
35
+ // Nameservers for a domain need both a NS record on the domain and an A record for themselves
36
+ tmpDomain . records . push ( `${ domain } ,ns,${ tmpNameserverParts [ 0 ] } ` )
37
+ tmpDomain . records . push ( `${ tmpNameserverParts [ 0 ] } ,a,${ tmpNameserverParts [ 1 ] } ` )
38
+ }
39
+ for ( var tmpRecord in record ) {
40
+ tmpDomain . records . push ( tmpRecord )
41
+ }
42
+ domains . push ( tmpDomain )
43
+ } else {
44
+ domains = JSON . parse ( Deno . readTextFileSync ( dataFile ) ) ;
34
45
}
35
46
36
47
console . log ( `Building transaction...` ) ;
@@ -44,51 +55,57 @@ const generate = new Command()
44
55
45
56
lucid . selectWalletFrom ( { address : sourceAddress } ) ;
46
57
47
- let outDatumRecords = [ ]
48
- records . forEach ( ( tmpRecord ) => {
49
- const recordParts = tmpRecord . split ( "," )
50
- if ( recordParts . length == 3 ) {
51
- outDatumRecords . push ( new Constr (
52
- 1 ,
53
- [
54
- fromText ( recordParts [ 0 ] ) ,
55
- fromText ( recordParts [ 1 ] ) ,
56
- fromText ( recordParts [ 2 ] ) ,
57
- ] ,
58
- ) )
59
- } else if ( recordParts . length == 4 ) {
60
- outDatumRecords . push ( new Constr (
61
- 1 ,
62
- [
63
- fromText ( recordParts [ 0 ] ) ,
64
- BigInt ( parseInt ( recordParts [ 1 ] ) ) ,
65
- fromText ( recordParts [ 2 ] ) ,
66
- fromText ( recordParts [ 3 ] ) ,
67
- ] ,
68
- ) )
69
- } else {
70
- console . log ( `Invalid record: ${ tmpRecord } ` )
71
- Deno . exit ( 1 )
72
- }
73
- } )
74
-
75
- const outDatum = new Constr ( 1 , [
76
- fromText ( domain ) ,
77
- outDatumRecords ,
78
- ] ) ;
58
+ try {
59
+ let tx = await lucid
60
+ . newTx ( )
79
61
80
- const outDatumEncoded = Data . to ( outDatum ) ;
62
+ for ( var domain of domains ) {
63
+ let outDatumRecords = [ ]
64
+ domain . records . forEach ( ( tmpRecord ) => {
65
+ const recordParts = tmpRecord . split ( "," )
66
+ if ( recordParts . length == 3 ) {
67
+ outDatumRecords . push ( new Constr (
68
+ 1 ,
69
+ [
70
+ fromText ( recordParts [ 0 ] ) ,
71
+ fromText ( recordParts [ 1 ] ) ,
72
+ fromText ( recordParts [ 2 ] ) ,
73
+ ] ,
74
+ ) )
75
+ } else if ( recordParts . length == 4 ) {
76
+ outDatumRecords . push ( new Constr (
77
+ 1 ,
78
+ [
79
+ fromText ( recordParts [ 0 ] ) ,
80
+ BigInt ( parseInt ( recordParts [ 1 ] ) ) ,
81
+ fromText ( recordParts [ 2 ] ) ,
82
+ fromText ( recordParts [ 3 ] ) ,
83
+ ] ,
84
+ ) )
85
+ } else {
86
+ console . log ( `Invalid record: ${ tmpRecord } ` )
87
+ Deno . exit ( 1 )
88
+ }
89
+ } )
90
+
91
+ const outDatum = new Constr ( 1 , [
92
+ fromText ( domain . origin ) ,
93
+ outDatumRecords ,
94
+ ] ) ;
95
+
96
+ const outDatumEncoded = Data . to ( outDatum ) ;
97
+
98
+ //console.log(`outDatumEncoded = ${outDatumEncoded}`)
81
99
82
- //console.log(`outDatumEncoded = ${outDatumEncoded}`)
100
+ tx = tx
101
+ . payToAddressWithData (
102
+ destAddress ,
103
+ { inline : outDatumEncoded } ,
104
+ { lovelace : 2_000_000 } ,
105
+ ) ;
106
+ }
83
107
84
- try {
85
- const txOut = await lucid
86
- . newTx ( )
87
- . payToAddressWithData (
88
- destAddress ,
89
- { inline : outDatumEncoded } ,
90
- { lovelace : 2_000_000 } ,
91
- )
108
+ const txOut = await tx
92
109
// 10 minutes
93
110
. validTo ( Date . now ( ) + 600_000 )
94
111
. complete ( ) ;
@@ -101,7 +118,7 @@ const generate = new Command()
101
118
const txJson = JSON . stringify ( txJsonObj )
102
119
103
120
if ( output === undefined ) {
104
- output = `./tx-cdnsd-test-data-${ domain } - ${ txOut . toHash ( ) } .json`
121
+ output = `./tx-cdnsd-test-data-${ txOut . toHash ( ) } .json`
105
122
}
106
123
Deno . writeTextFileSync ( output , txJson )
107
124
0 commit comments