Skip to content

Commit

Permalink
Merge pull request #214 from zing-rsa/change/emulator-datums
Browse files Browse the repository at this point in the history
allow datum in emulator genesis utxo #213
  • Loading branch information
alessandrokonrad committed Aug 28, 2023
2 parents 9986d05 + c08a45e commit 0c8fec0
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/provider/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DatumHash,
Delegation,
Lovelace,
OutputData,
OutRef,
PoolId,
ProtocolParameters,
Expand Down Expand Up @@ -48,21 +49,45 @@ export class Emulator implements Provider {
datumTable: Record<DatumHash, Datum> = {};

constructor(
accounts: { address: Address; assets: Assets }[],
accounts: {
address: Address;
assets: Assets;
outputData?: OutputData;
}[],
protocolParameters: ProtocolParameters = PROTOCOL_PARAMETERS_DEFAULT,
) {
const GENESIS_HASH = "00".repeat(32);
this.blockHeight = 0;
this.slot = 0;
this.time = Date.now();
this.ledger = {};
accounts.forEach(({ address, assets }, index) => {
accounts.forEach(({ address, assets, outputData }, index) => {
if (
[
outputData?.hash,
outputData?.asHash,
outputData?.inline,
].filter((b) => b)
.length > 1
) {
throw new Error(
"Not allowed to set hash, asHash and inline at the same time.",
);
}

this.ledger[GENESIS_HASH + index] = {
utxo: {
txHash: GENESIS_HASH,
outputIndex: index,
address,
assets,
datumHash: outputData?.asHash
? C.hash_plutus_data(
C.PlutusData.from_bytes(fromHex(outputData.asHash)),
).to_hex()
: outputData?.hash,
datum: outputData?.inline,
scriptRef: outputData?.scriptRef,
},
spent: false,
};
Expand Down

0 comments on commit 0c8fec0

Please sign in to comment.