Skip to content

Commit

Permalink
work on adding nomination function
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Jul 1, 2024
1 parent 377cb12 commit 68f0675
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
50 changes: 50 additions & 0 deletions miner/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
incrementNonceV2,
readValidator,
readValidators,
readNewSpendValidator,
sha256,
calculateInterlink,
} from './utils';
Expand Down Expand Up @@ -1296,6 +1297,55 @@ app
encoding: 'utf8',
}),
);

const newSpend = readNewSpendValidator();

const utxos = (await lucid.wallet.getUtxos()).sort((a, b) => {
return a.txHash.localeCompare(b.txHash) || a.outputIndex - b.outputIndex;
});

const utxoRef = utxos[0];

const newSpendApplied = applyParamsToScript(newSpend.script, [
tunav2ValidatorHash,
new Constr(0, [new Constr(0, [utxoRef.txHash]), BigInt(utxoRef.outputIndex)]),
]);

const newSpendScript: Script = { script: newSpendApplied, type: 'PlutusV2' };

const newSpendAddress = lucid.utils.validatorToAddress(newSpendScript);
const newSpendHash = lucid.utils.validatorToScriptHash(newSpendScript);

// NominateUpgrade(validatorHash, outputIndex)
const mintNominateRedeemer = new Constr(3, [newSpendHash, 0n]);

const spendNominateRedeemer = new Constr(2, []);

const setupTx = await lucid
.newTx()
.collectFrom([utxos[1]])
.payToContract(newSpendAddress, { inline: Data.to(0n) }, { lovelace: 1500000n })
.complete();

const setupTxSigned = await setupTx.sign().complete();

await setupTxSigned.submit();

lucid.awaitTx(setupTxSigned.toHash());

const contractUtxo = await lucid.utxosByOutRef([
{ txHash: setupTxSigned.toHash(), outputIndex: 0 },
]);

const nominateTx = await lucid
.newTx()
.collectFrom(contractUtxo, Data.to(spendNominateRedeemer))
.mintAssets(
{ [tunav2ValidatorHash + fromText('NOMA') + newSpendHash]: 1n },
Data.to(mintNominateRedeemer),
)
.payToContract(address, outputData, assets)
.complete();
});

app.parse();
9 changes: 9 additions & 0 deletions miner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export function readValidators(): SpendingValidator[] {
];
}

export function readNewSpendValidator(): SpendingValidator {
const spendValidator = blueprint.validators.filter((v) => v.title === 'new_spend.mine')[0];

return {
type: 'PlutusV2',
script: spendValidator.compiledCode,
};
}

export function printExecutionDetails(tx: TxSigned, name: string) {
const redeemers = tx.txSigned.witness_set().redeemers()!;
let steps = 0;
Expand Down

0 comments on commit 68f0675

Please sign in to comment.