Skip to content

Commit

Permalink
fix: update stake transaction example
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Dec 12, 2023
1 parent 2e8e6a0 commit a2579f5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions example/stake_transaction_example.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
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(
'0000000000000000000000000000000000000000000000000000000000000000:0');

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: [
Input(outputPointer: outputPointer),
],
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
Expand Down

0 comments on commit a2579f5

Please sign in to comment.