Skip to content

Commit

Permalink
0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-nuzzi committed Oct 23, 2024
1 parent bee2cae commit c4d170c
Show file tree
Hide file tree
Showing 7 changed files with 9,459 additions and 9,438 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harmoniclabs/plu-ts",
"version": "0.8.2-dev2",
"version": "0.8.2",
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -76,8 +76,8 @@
"@harmoniclabs/crypto": "^0.2.4",
"@harmoniclabs/obj-utils": "^1.0.0",
"@harmoniclabs/pair": "^1.0.0",
"@harmoniclabs/plu-ts-offchain": "0.1.16-dev2",
"@harmoniclabs/plu-ts-onchain": "^0.3.2-dev2",
"@harmoniclabs/plu-ts-offchain": "0.1.16",
"@harmoniclabs/plu-ts-onchain": "^0.3.2",
"@harmoniclabs/plutus-data": "^1.2.4",
"@harmoniclabs/plutus-machine": "^2.0.1",
"@harmoniclabs/uint8array-utils": "^1.0.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/offchain/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/offchain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harmoniclabs/plu-ts-offchain",
"version": "0.1.16-dev2",
"version": "0.1.16",
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -62,7 +62,7 @@
"@harmoniclabs/bip32_ed25519": "^0.1.2",
"@harmoniclabs/bytestring": "^1.0.0",
"@harmoniclabs/cardano-costmodels-ts": "^1.2.0",
"@harmoniclabs/cardano-ledger-ts": "^0.2.5",
"@harmoniclabs/cardano-ledger-ts": "^0.2.6",
"@harmoniclabs/cbor": "^1.3.0",
"@harmoniclabs/pair": "^1.0.0",
"@harmoniclabs/plutus-data": "^1.2.4",
Expand Down
60 changes: 41 additions & 19 deletions packages/offchain/src/TxBuilder/TxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class TxBuilder

if( nRdmrs === 0 ){
this.assertMinOutLovelaces( tx.body.outputs );
return tx
return tx;
};

let txOuts: TxOut[] = new Array( outs.length + 1 );
Expand Down Expand Up @@ -1344,24 +1344,25 @@ export class TxBuilder

const txOuts: TxOut[] = new Array( outs.length + 1 );
outs.forEach( (txO,i) => txOuts[i] = txO.clone() );
txOuts[txOuts.length - 1] = (
new TxOut({
address: change.address,
value: Value.sub(
totInputValue,
Value.add(
requiredOutputValue,
Value.lovelaces( minFee )
)
),
datum: change.datum ? (
change.datum instanceof Hash32 ?
change.datum :
forceData( change.datum )
): undef,
refScript: change.refScript
})
);
const changeOutput =new TxOut({
address: change.address,
value: Value.sub(
totInputValue,
Value.add(
requiredOutputValue,
Value.lovelaces( minFee )
)
),
datum: change.datum ? (
change.datum instanceof Hash32 ?
change.datum :
forceData( change.datum )
): undef,
refScript: change.refScript
});
txOuts[txOuts.length - 1] = changeOutput;

this.assertCorrectChangeOutput( changeOutput );

let tx = new Tx({
...dummyTx,
Expand All @@ -1385,6 +1386,27 @@ export class TxBuilder
};
}

assertCorrectChangeOutput(changeOutput: TxOut): void
{
if( changeOutput.value.lovelaces < 0 )
throw new Error("not enough input lovelaces to cover the output value and fee");

for( const { assets, policy } of changeOutput.value )
{
if( policy === "" ) continue;
for( const { quantity, name } of assets )
{
if( quantity < 0 )
{
console.dir( changeOutput.value.toJson(), { depth: Infinity } );
throw new Error(
`not enough ${policy.toString()}.${toHex( name )} in input to cover the total output`
);
}
}
}
}

findCollaterals( utxos: UTxO[], targetCollateralLovelaces: number | bigint = 10_000_000 ): UTxO[]
{
const grouped: { [pkh: string]: UTxO[] } = {};
Expand Down
Loading

0 comments on commit c4d170c

Please sign in to comment.