From a2579f55e12e6f0431b71a0886ab7e95fe4f19c5 Mon Sep 17 00:00:00 2001 From: parodyBit Date: Tue, 12 Dec 2023 06:41:50 -0700 Subject: [PATCH] fix: update stake transaction example --- example/stake_transaction_example.dart | 31 +++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/example/stake_transaction_example.dart b/example/stake_transaction_example.dart index dfe4e5e..2909cfa 100644 --- a/example/stake_transaction_example.dart +++ b/example/stake_transaction_example.dart @@ -1,6 +1,7 @@ import 'package:witnet/node.dart'; import 'package:witnet/schema.dart'; import 'package:witnet/src/constants.dart'; +import 'package:witnet/src/utils/transformations/transformations.dart'; import 'package:witnet/witnet.dart'; var outputPointer = OutputPointer.fromString( @@ -8,13 +9,26 @@ var outputPointer = OutputPointer.fromString( void main() async { /// connect to local node rpc - NodeClient nodeClient = NodeClient(address: "127.0.0.1", port: 21338); + // NodeClient nodeClient = NodeClient(address: "127.0.0.1", port: 21338); + // String mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; /// load node xprv for the default mnemonic - /// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" - Xprv xprv = Xprv.fromXprv( + Xprv masterNode = Xprv.fromXprv( "xprv1qpujxsyd4hfu0dtwa524vac84e09mjsgnh5h9crl8wrqg58z5wmsuqqcxlqmar3fjhkprndzkpnp2xlze76g4hu7g7c4r4r2m2e6y8xlvu566tn6"); + Xprv withdrawer = + masterNode + / KEYPATH_PURPOSE + / KEYPATH_COIN_TYPE + / KEYPATH_ACCOUNT + / EXTERNAL_KEYCHAIN + / 0; + + /// The 20 byte Public Key Hash of the withdrawer + String pkh = bytesToHex(withdrawer.privateKey.publicKey.publicKeyHash); + /// The authorization by the node + KeyedSignature authorization = signHash(pkh, masterNode.privateKey); + /// build stake transaction body StakeBody body = StakeBody( inputs: [ @@ -22,18 +36,19 @@ void main() async { ], output: StakeOutput( value: MINIMUM_STAKEABLE_AMOUNT_WITS, - authorization: KeyedSignature(), + authorization: authorization, ), ); /// build and sign stake transaction StakeTransaction stake = StakeTransaction( - body: body, signatures: [signHash(body.transactionId, xprv.privateKey)]); + body: body, signatures: [signHash(body.transactionId, masterNode.privateKey)]); - /// send stake transaction - var response = await nodeClient.inventory(stake.jsonMap()); + /// The Stake Transaction ID + print(stake.transactionID); - print(response); + /// send stake transaction + /// var response = await nodeClient.inventory(stake.jsonMap()); } /// Sign Hash