@@ -296,7 +296,8 @@ async function main() {
296
296
* @param {Uint8Array } txHashBytes
297
297
*/
298
298
sign : async function ( privKeyBytes , txHashBytes ) {
299
- let sigOpts = { canonical : true , extraEntropy : true } ;
299
+ // extraEntropy set to null to make gobject transactions idempotent
300
+ let sigOpts = { canonical : true , extraEntropy : null } ;
300
301
let sigBytes = await Secp256k1 . sign ( txHashBytes , privKeyBytes , sigOpts ) ;
301
302
302
303
return sigBytes ;
@@ -323,11 +324,9 @@ async function main() {
323
324
console . log ( "Collateral Address (source of 1 DASH network fee):" ) ;
324
325
console . log ( collateralAddr ) ;
325
326
326
- // we can set txid to short circuit for testing
327
327
let txid = "" ;
328
- // ./bin/gobject-prepare.js 1 3 100 https://example.com/proposal-00 proposal-00 yPPy7Z5RQj46SnFtuFXyT6DFAygxESPR7K ./yjZxu7SJAwgSm1JtWybuQRYQDx34z8P2Z7.wif
329
- // txid = "10d9862feb6eac6cf6fa653589e39b60a0ed640bae4140c51c35401ffe019479";
330
- if ( ! txid ) {
328
+ let txInfoSigned ;
329
+ {
331
330
let utxosResult = await rpc . getaddressutxos ( {
332
331
addresses : [ collateralAddr ] ,
333
332
} ) ;
@@ -338,7 +337,7 @@ async function main() {
338
337
// @type {Array<DashTx.TxOutput> } */
339
338
let outputs = [ { memo : gobjIdForward , satoshis : 100000000 } ] ;
340
339
let txInfo = { inputs, outputs } ;
341
- let txInfoSigned = await dashTx . hashAndSignAll ( txInfo ) ;
340
+ txInfoSigned = await dashTx . hashAndSignAll ( txInfo ) ;
342
341
console . log ( utxosResult ) ;
343
342
//
344
343
@@ -350,7 +349,36 @@ async function main() {
350
349
console . log ( "Signed Collateral Transaction ID:" ) ;
351
350
txid = await DashTx . getId ( txInfoSigned . transaction ) ;
352
351
console . log ( txid ) ;
352
+ }
353
353
354
+ async function check ( ) {
355
+ let gobjResult = await rpc
356
+ . request ( "/" , {
357
+ method : "gobject" ,
358
+ params : [ "check" , gobj . dataHex ] ,
359
+ } )
360
+ . catch (
361
+ /** @param {any } err */ function ( err ) {
362
+ console . error ( err . message ) ;
363
+ console . error ( err . code ) ;
364
+ console . error ( err ) ;
365
+ // invalid burn hash
366
+ return null ;
367
+ } ,
368
+ ) ;
369
+
370
+ // { result: { 'Object status': 'OK' }, error: null, id: 5542 }
371
+ if ( gobjResult ?. result ?. [ "Object status" ] !== "OK" ) {
372
+ throw new Error ( `gobject failed: ${ gobjResult . result . error } ` ) ;
373
+ }
374
+ return gobjResult ;
375
+ }
376
+
377
+ await check ( ) ;
378
+
379
+ // ./bin/gobject-prepare.js 1 3 100 https://example.com/proposal-00 proposal-00 yPPy7Z5RQj46SnFtuFXyT6DFAygxESPR7K ./yjZxu7SJAwgSm1JtWybuQRYQDx34z8P2Z7.wif
380
+ // set to false to short circuit for testing
381
+ if ( true ) {
354
382
let txResult = await rpc . request ( "/" , {
355
383
method : "sendrawtransaction" ,
356
384
params : [ txInfoSigned . transaction ] ,
@@ -395,25 +423,6 @@ async function main() {
395
423
await DashGov . utils . sleep ( 5000 ) ;
396
424
}
397
425
398
- // async function check() {
399
- // let gobjResult = await rpc
400
- // .request("/", {
401
- // method: "gobject",
402
- // params: ["check", gobj.dataHex],
403
- // })
404
- // .catch(
405
- // /** @param {any } err */ function (err) {
406
- // console.error(err.message);
407
- // console.error(err.code);
408
- // console.error(err);
409
- // // invalid collateral hash
410
- // return null;
411
- // },
412
- // );
413
-
414
- // return gobjResult;
415
- // }
416
-
417
426
async function submit ( ) {
418
427
let req = {
419
428
method : "gobject" ,
0 commit comments