Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
feat: migrating tx builder type
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Jun 13, 2024
1 parent aba7a3a commit 18cf23c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@meshsdk/common",
"description": "Cardano common utils & constants for Mesh SDK",
"version": "1.0.0-alpha.10",
"version": "1.0.0-alpha.12",
"license": "Apache-2.0",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down
22 changes: 18 additions & 4 deletions packages/common/src/builder/data/plutus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,24 @@ export const maybeStakingHash = (
conStr0([conStr0([builtinByteString(stakeCredential)])]),
]);
};
export const pubKeyAddress = (bytes: string, stakeCredential?: string): PubKeyAddress =>
conStr0([conStr0([builtinByteString(bytes)]), maybeStakingHash(stakeCredential || '')]);
export const scriptAddress = (bytes: string, stakeCredential?: string): ScriptAddress =>
conStr0([conStr1([builtinByteString(bytes)]), maybeStakingHash(stakeCredential || '')]);
export const pubKeyAddress = (
bytes: string,
stakeCredential?: string,
isScriptCredential = false,
): PubKeyAddress =>
conStr0([
conStr0([builtinByteString(bytes)]),
maybeStakingHash(stakeCredential || '', isScriptCredential),
]);
export const scriptAddress = (
bytes: string,
stakeCredential?: string,
isScriptCredential = false,
): ScriptAddress =>
conStr0([
conStr1([builtinByteString(bytes)]),
maybeStakingHash(stakeCredential || '', isScriptCredential),
]);
export const assetClass = (policyId: string, assetName: string): AssetClass =>
conStr0([currencySymbol(policyId), tokenName(assetName)]);

Expand Down
1 change: 1 addition & 0 deletions packages/common/src/builder/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const emptyTxBuilderBody = (): MeshTxBuilderBody => ({
validityRange: {},
certificates: [],
signingKey: [],
withdrawals: [],
});

export interface IMeshSerializer {
Expand Down
34 changes: 23 additions & 11 deletions packages/common/src/builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export type MeshTxBuilderBody = {
collaterals: PubKeyTxIn[];
requiredSignatures: string[];
referenceInputs: RefTxIn[];
withdrawals: Withdrawal[];
mints: MintItem[];
changeAddress: string;
changeDatum?: BuilderData;
metadata: Metadata[];
validityRange: ValidityRange;
certificates: Certificate[];
signingKey: string[];
extraInputs: UTxO[];
selectionThreshold: number;
certificates: Certificate[];
// withdrawals?: Record<StakeCredential, number>;
};

export type TxIn = PubKeyTxIn | ScriptTxIn;
Expand All @@ -37,15 +37,7 @@ export type ScriptTxIn = {
};

export type ScriptTxInParameter = {
scriptSource?:
| {
type: 'Provided';
script: PlutusScript;
}
| {
type: 'Inline';
txInInfo: ScriptSourceInfo;
};
scriptSource?: ScriptSource;
datumSource?:
| {
type: 'Provided';
Expand All @@ -59,6 +51,16 @@ export type ScriptTxInParameter = {
redeemer?: Redeemer;
};

export type ScriptSource =
| {
type: 'Provided';
script: PlutusScript;
}
| {
type: 'Inline';
txInInfo: ScriptSourceInfo;
};

export type ScriptSourceInfo = {
txHash: string;
txIndex: number;
Expand Down Expand Up @@ -137,6 +139,16 @@ export type Certificate =
| { type: 'DeregisterStake'; stakeKeyHash: string }
| { type: 'RetirePool'; poolId: string; epoch: number };

export type Withdrawal =
| { type: 'PubKeyWithdrawal'; address: string; coin: number }
| {
type: 'PlutusScriptWithdrawal';
address: string;
coin: number;
scriptSource?: ScriptSource;
redeemer?: Redeemer;
};

// Utilities

export type RequiredWith<T, K extends keyof T> = Required<T> & {
Expand Down

0 comments on commit 18cf23c

Please sign in to comment.