Skip to content

Needs test for L2 AssetLockProof TXΒ #86

@coolaj86

Description

@coolaj86

We updated the other tests to work with the L2 messages, but forgot to put a test fixture in for the AssetLock specifically.

Here's the code that can produce the signed payload, verified by virtue of being broadcast to the network and accepted.

  let utxos = await DashTx.utils.rpc(rpcAuthUrl, "getaddressutxos", {
    addresses: [addr],
  });
  let total = DashTx.sum(utxos);
  console.log();
  console.log(`utxos (${total})`);
  console.log(utxos);

  // TODO which hd paths to use for which addresses?
  let creditOutputs = [{ satoshis: total - 10000, pubKeyHash: pkh }];
  let totalCredits = DashTx.sum(creditOutputs);
  let burnOutput = { satoshis: totalCredits, pubKeyHash: pkh };
  //@ts-ignore - TODO add types
  let assetLockScript = DashPlatform.Tx.packAssetLock({
    creditOutputs,
  });

  let txDraft = {
    version: L1_VERSION_PLATFORM,
    type: TYPE_ASSET_LOCK,
    inputs: utxos,
    outputs: [burnOutput],
    extraPayload: assetLockScript,
  };
  console.log();
  console.log(`txDraft:`);
  console.log(txDraft);

  txDraft.inputs.sort(DashTx.sortInputs);
  txDraft.outputs.sort(DashTx.sortOutputs);
  let vout = txDraft.outputs.indexOf(burnOutput);

  let vin = 0;
  let txSigHash = DashTx.createForSig(txDraft, vin, DashTx.SIGHASH_DEFAULT);
  let txHex = DashTx.serialize(txSigHash, _sigHashType);
  console.log(txHex);

  let txSigned = await dashTx.hashAndSignAll(txDraft);
  console.log();
  console.log(`txSigned:`);
  console.log(txSigned);

  let txid = await DashTx.utils.rpc(
    rpcAuthUrl,
    "sendrawtransaction",
    txSigned.transaction,
  );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions