Skip to content

Commit

Permalink
TxBuilderRunner propose methods
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-nuzzi committed Mar 26, 2024
1 parent b34ef82 commit 94a2dd4
Show file tree
Hide file tree
Showing 14 changed files with 790 additions and 128 deletions.
8 changes: 4 additions & 4 deletions packages/offchain/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/offchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@harmoniclabs/cardano-costmodels-ts": "^1.1.0",
"@harmoniclabs/plutus-machine": "^1.1.2",
"@harmoniclabs/uplc": "^1.2.3",
"@harmoniclabs/cardano-ledger-ts": "^0.2.0-dev2"
"@harmoniclabs/cardano-ledger-ts": "^0.2.0-dev3"
},
"devDependencies": {
"@babel/preset-env": "^7.18.6",
Expand Down
27 changes: 1 addition & 26 deletions packages/offchain/src/TxBuilder/TxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,6 @@ export class TxBuilder
refScript: change.refScript
})
);
console.log(
txOuts[ txOuts.length - 1 ].value.toJson(),
totInputValue.toJson(),
requiredOutputValue.toJson(),
fee,
minFee,
totExBudget.toJson(),
memRational.toNumber(),
cpuRational.toNumber()
)

tx = new Tx({
...tx,
Expand Down Expand Up @@ -1110,7 +1100,7 @@ export class TxBuilder
forceBigUInt( invalidAfter ),
auxDataHash: auxData?.hash,
scriptDataHash: getScriptDataHash( redeemers, datumsScriptData, languageViews ),
network
network,
}),
witnesses: dummyTxWitnesses,
auxiliaryData: auxData,
Expand Down Expand Up @@ -1160,21 +1150,6 @@ export class TxBuilder
})
});

console.log(
JSON.stringify(
tx.body.outputs.map( o => o.toJson() ),
undef,
2
)
);
console.log(
JSON.stringify(
tx.body.toJson(),
undef,
2
)
);

return {
tx,
scriptsToExec,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Hash28, PoolKeyHash, Address, AddressStr } from "@harmoniclabs/cardano-ledger-ts";
import { decodeBech32 } from "@harmoniclabs/crypto";
import { fromHex } from "@harmoniclabs/uint8array-utils";

export type CanBePoolKeyHash = Hash28 | `pool1${string}` | `pool_test1${string}` | string /* hex */ | Uint8Array;

export function forcePoolKeyHash( canBe: CanBePoolKeyHash ): PoolKeyHash
{
if( typeof canBe === "string" )
{
if( canBe.startsWith("pool") )
{
const [ _hrp, decoded ] = decodeBech32( canBe );

return new PoolKeyHash( new Uint8Array( decoded ) );
}
return new PoolKeyHash( fromHex( canBe ) );
}
return new PoolKeyHash( canBe );
}
43 changes: 43 additions & 0 deletions packages/offchain/src/TxBuilder/TxBuilderRunner/CanBeStakeCreds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { StakeAddress, Credential, StakeAddressBech32, StakeCredentials, Script, PlutusScriptType, StakeValidatorHash, CredentialType, Hash28 } from "@harmoniclabs/cardano-ledger-ts";

export type CanBeStakeCreds
= StakeAddress
| StakeAddressBech32
| StakeCredentials
| Script<PlutusScriptType>
| Credential;

export function forceStakeCreds( creds: CanBeStakeCreds ): Credential
{
if( creds instanceof Credential ) return creds;

if( typeof creds === "string" )
{
if( !creds.startsWith("stake") )
{
throw new Error("invalid bech32 stake address");
}
creds = StakeAddress.fromString( creds );
}
if( creds instanceof StakeAddress )
{
return creds.toCredential();
}

if( creds instanceof Script )
{
return Credential.script(
new StakeValidatorHash( creds.hash )
);
}

if( creds.type === "pointer" )
{
throw new Error("pointer stake credentials not supported");
}

return new Credential(
creds.type === "script" ? CredentialType.Script : CredentialType.KeyHash,
creds.hash as Hash28
);
}
Loading

0 comments on commit 94a2dd4

Please sign in to comment.