Skip to content

Commit

Permalink
updating fork action
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Jun 3, 2024
1 parent e2fd176 commit 4bd83a1
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 56 deletions.
41 changes: 33 additions & 8 deletions miner/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Translucent,
type Script,
toHex,
UTxO,
} from 'translucent-cardano/index';
import fs from 'fs';
import crypto from 'crypto';
Expand All @@ -25,6 +26,7 @@ import {
getDifficultyAdjustement,
incrementU8Array,
readValidator,
readValidators,
sha256,
} from './utils';

Expand Down Expand Up @@ -383,7 +385,7 @@ app
.addOption(ogmiosUrlOption)
.addOption(previewOption)
.action(async ({ preview, ogmiosUrl, kupoUrl }) => {
const unAppliedValidator = readValidator();
const [fortunaV1, forkValidator, fortunaV2Mint, fortunaV2Spend] = readValidators();

const provider = new Kupmios(kupoUrl, ogmiosUrl);
const lucid = await Translucent.new(provider, preview ? 'Preview' : 'Mainnet');
Expand All @@ -400,20 +402,43 @@ app
BigInt(utxos[0].outputIndex),
]);

const appliedValidator = applyParamsToScript(unAppliedValidator.script, [initOutputRef]);
const fortunaV1Hash = lucid.utils.validatorToScriptHash(fortunaV1);

const validator: Script = {
const fortunaV1Address = lucid.utils.validatorToAddress(fortunaV1);

const forkValidatorApplied: Script = {
type: 'PlutusV2',
script: appliedValidator,
script: applyParamsToScript(forkValidator.script, [initOutputRef, fortunaV1Hash]),
};

const bootstrapHash = toHex(await sha256(await sha256(fromHex(Data.to(initOutputRef)))));
const forkValidatorHash = lucid.utils.validatorToScriptHash(forkValidatorApplied);

const validatorAddress = lucid.utils.validatorToAddress(validator);
const tunaV2MintApplied: Script = {
type: 'PlutusV2',
script: applyParamsToScript(fortunaV2Mint.script, [fortunaV1Hash, forkValidatorHash]),
};

const validatorHash = lucid.utils.validatorToScriptHash(validator);
const tunaV2MintAppliedHash = lucid.utils.validatorToScriptHash(tunaV2MintApplied);

const masterToken = { [validatorHash + fromText('lord tuna')]: 1n };
const tunaV2SpendApplied: Script = {
type: 'PlutusV2',
script: applyParamsToScript(fortunaV2Spend.script, [tunaV2MintAppliedHash]),
};

const tunaV2SpendAppliedHash = lucid.utils.validatorToScriptHash(tunaV2SpendApplied);

const lastestV1Block: UTxO = (
await lucid.utxosAtWithUnit(fortunaV1Address, fortunaV1Hash + fromText('lord tuna'))
)[0];

const lastestV1BlockData = Data.from(lastestV1Block.datum!) as Constr<bigint>;

const blockNumber = lastestV1BlockData.fields[0];

const masterTokensV2 = {
[tunaV2MintAppliedHash + 'TUNA' + tunaV2SpendAppliedHash]: 1n,
[tunaV2MintAppliedHash + 'COUNTER' + blockNumber]: 1n,
};

const timeNow = Number((Date.now() / 1000).toFixed(0)) * 1000 - 60000;

Expand Down
26 changes: 26 additions & 0 deletions miner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ export function readValidator(): SpendingValidator {
};
}

export function readValidators(): SpendingValidator[] {
const fortunaV1 = blueprint.validators.filter((v) => v.title === 'tunav1.spend')[0];
const forkValidator = blueprint.validators.filter((v) => v.title === 'simplerfork.fork')[0];
const fortunaV2Mint = blueprint.validators.filter((v) => v.title === 'tunav2.tuna')[0];
const fortunaV2Spend = blueprint.validators.filter((v) => v.title === 'tunav2.mine')[0];

return [
{
type: 'PlutusV2',
script: toHex(cbor.encode(fromHex(fortunaV1.compiledCode))),
},
{
type: 'PlutusV2',
script: toHex(cbor.encode(fromHex(forkValidator.compiledCode))),
},
{
type: 'PlutusV2',
script: toHex(cbor.encode(fromHex(fortunaV2Mint.compiledCode))),
},
{
type: 'PlutusV2',
script: toHex(cbor.encode(fromHex(fortunaV2Spend.compiledCode))),
},
];
}

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

0 comments on commit 4bd83a1

Please sign in to comment.