Skip to content

Commit

Permalink
feat: extracting constants to common
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed May 17, 2024
1 parent 47c63a3 commit 68d466d
Show file tree
Hide file tree
Showing 72 changed files with 5,829 additions and 10,346 deletions.
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@meshsdk/core": "1.5.16"
},
"dependencies": {
"@harmoniclabs/plu-ts": "0.2.2",
"@meshsdk/mesh-csl": "^0.0.4"
}
}
6 changes: 3 additions & 3 deletions packages/contracts/src/escrow/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MeshEscrowContract extends MeshTxInitiator {
await this.mesh
.txOut(scriptAddr, escrowAmount)
.txOutInlineDatumValue(
initiateEscrowDatum(walletAddress, escrowAmount),
initiateEscrowDatum(walletAddress, escrowAmount) as any,
'JSON'
)
.changeAddress(walletAddress)
Expand Down Expand Up @@ -169,7 +169,7 @@ export class MeshEscrowContract extends MeshTxInitiator {
)
.spendingReferenceTxInInlineDatumPresent()
.txInRedeemerValue(
recipientDepositRedeemer(walletAddress, depositAmount),
recipientDepositRedeemer(walletAddress, depositAmount) as any,
{
mem: 7_000_000,
steps: 3_000_000_000,
Expand All @@ -178,7 +178,7 @@ export class MeshEscrowContract extends MeshTxInitiator {
)
.txInScript(this.scriptCbor)
.txOut(scriptAddr, escrowAmount)
.txOutInlineDatumValue(outputDatum, 'JSON')
.txOutInlineDatumValue(outputDatum as any, 'JSON')
.changeAddress(walletAddress)
.txInCollateral(
collateral.input.txHash,
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/marketplace/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class MeshMarketplaceContract extends MeshTxInitiator {

await this.mesh
.txOut(scriptAddr, tokenForSale)
.txOutInlineDatumValue(outputDatum, 'JSON')
.txOutInlineDatumValue(outputDatum as any, 'JSON')
.changeAddress(walletAddress)
.selectUtxosFrom(selectedUtxos)
.complete();
Expand Down Expand Up @@ -219,7 +219,7 @@ export class MeshMarketplaceContract extends MeshTxInitiator {
.spendingReferenceTxInRedeemerValue(mConStr1([]))
.txInScript(this.scriptCbor)
.txOut(scriptAddr, tokenForSale)
.txOutInlineDatumValue(outputDatum, 'JSON')
.txOutInlineDatumValue(outputDatum as any, 'JSON')
.changeAddress(walletAddress)
.requiredSignerHash(serializeBech32Address(walletAddress).pubKeyHash)
.txInCollateral(
Expand Down
7 changes: 4 additions & 3 deletions packages/contracts/src/payment-splitter/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
list,
} from '@meshsdk/mesh-csl';
import blueprint from './aiken-workspace/plutus.json';
import { PlutusScript } from '@meshsdk/common';

export class MeshPaymentSplitterContract extends MeshTxInitiator {
wrapPayees = (payees: string[]) =>
Expand Down Expand Up @@ -49,7 +50,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {

const { walletAddress } = await this.getWalletInfoForTx();

const script = {
const script: PlutusScript = {
code: this.scriptCbor(),
version: 'V2',
};
Expand Down Expand Up @@ -83,7 +84,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {

const { walletAddress, collateral } = await this.getWalletInfoForTx();

const script = {
const script: PlutusScript = {
code: this.scriptCbor(),
version: 'V2',
};
Expand Down Expand Up @@ -112,7 +113,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {
value: utxo,
script: script,
datum: datum,
redeemer: redeemer,
redeemer: redeemer as any, // TODO: fix this cast any
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Card from '../../../ui/card';
import Codeblock from '../../../ui/codeblock';
import { Transaction, KoiosProvider, resolveDataHash } from '@meshsdk/core';
import { useWallet, CardanoWallet } from '@meshsdk/react';
import { UTxO } from '@meshsdk/common';

export function evaluateTxLeft({ evaluatorName }) {
let code1 = ``;
Expand Down Expand Up @@ -96,14 +97,14 @@ export function evaluateTxRight({ evaluator }) {

const tx = new Transaction({ initiator: wallet })
.redeemValue({
value: assetUtxo,
value: assetUtxo as UTxO,
script: {
version: 'V1',
code: '4e4d01000033222220051200120011',
},
datum: 'supersecretmeshdemo',
})
.sendValue(address, assetUtxo)
.sendValue(address, assetUtxo as UTxO)
.setRequiredSigners([address]);

const unsignedTx = await tx.build();
Expand Down
1 change: 1 addition & 0 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "next lint"
},
"dependencies": {
"@harmoniclabs/plu-ts": "^0.3.0",
"@headlessui/react": "^1.6.6",
"@heroicons/react": "^2.0.10",
"@meshsdk/contracts": "1.0.0-beta.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/demo/pages/guides/custom-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function IntroSection() {

function HowItWorksSection() {
let codeIFetcher = ``;
codeIFetcher += `import type { AccountInfo, AssetMetadata, Protocol, UTxO } from '@mesh/types';\n\n`;
codeIFetcher += `import type { AccountInfo, AssetMetadata, Protocol, UTxO } from '@meshsdk/common';\n\n`;
codeIFetcher += `export interface IFetcher {\n`;
codeIFetcher += ` fetchAccountInfo(address: string): Promise<AccountInfo>;\n`;
codeIFetcher += ` fetchAddressUTxOs(address: string, asset?: string): Promise<UTxO[]>;\n`;
Expand Down Expand Up @@ -161,7 +161,7 @@ function StarterSection() {
code += ` AssetMetadata,\n`;
code += ` Protocol,\n`;
code += ` UTxO,\n`;
code += `} from "@mesh/types";\n`;
code += `} from "../common/types";\n`;
code += `\n`;
code += `export class NAMEProvider implements IFetcher, ISubmitter {\n`;
code += ` constructor(network: "") {\n`;
Expand Down
4 changes: 2 additions & 2 deletions packages/demo/pages/guides/pluts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
Transaction,
BlockfrostProvider,
} from '@meshsdk/core';
import type { PlutusScript, Data } from '@meshsdk/common';
import type { PlutusScript, Data, Redeemer } from '@meshsdk/common';
import { useWallet } from '@meshsdk/react';
import { useState } from 'react';

Expand Down Expand Up @@ -871,7 +871,7 @@ function HelloWorldUnlock() {
value: utxo,
script: script,
datum: utxo,
redeemer: redeemer,
redeemer: redeemer as any,
})
.sendValue(address, utxo)
.setRequiredSigners([address]);
Expand Down
16 changes: 8 additions & 8 deletions packages/demo/pages/guides/smart-contract-transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
resolvePlutusScriptAddress,
resolveDataHash,
} from '@meshsdk/core';
import type { Data, PlutusScript } from '@meshsdk/common';
import type { Data, PlutusScript, Redeemer } from '@meshsdk/common';
import { useEffect, useState } from 'react';
import Button from '../../components/ui/button';
import RunDemoResult from '../../components/common/runDemoResult';
Expand Down Expand Up @@ -919,7 +919,7 @@ const scriptCbor =
export function useMarketplacePlutus({ blockchainFetcher, network = 0 }) {
const { connected, wallet } = useWallet();
const [scriptAddress, setScriptAddress] = useState('');
const [script, setScript] = useState({});
const [script, setScript] = useState<PlutusScript>();

useEffect(() => {
const _script: PlutusScript = {
Expand Down Expand Up @@ -1035,9 +1035,9 @@ export function useMarketplacePlutus({ blockchainFetcher, network = 0 }) {
const tx = new Transaction({ initiator: wallet })
.redeemValue({
value: assetUtxo,
script: script,
script: script as PlutusScript,
datum: datumConstr,
redeemer: redeemer,
redeemer: redeemer as any, // TODO: Investigate why there is type error without casting any
})
.sendValue(addr, assetUtxo)
.setRequiredSigners([addr]);
Expand Down Expand Up @@ -1084,9 +1084,9 @@ export function useMarketplacePlutus({ blockchainFetcher, network = 0 }) {
const tx = new Transaction({ initiator: wallet })
.redeemValue({
value: assetUtxo,
script: script,
script: script as PlutusScript,
datum: datumConstr,
redeemer: redeemer,
redeemer: redeemer as any, // TODO: Investigate why there is type error without casting any
})
.sendValue(addr, assetUtxo)
.sendLovelace(sellerAddr, listPriceInLovelace.toString())
Expand Down Expand Up @@ -1143,9 +1143,9 @@ export function useMarketplacePlutus({ blockchainFetcher, network = 0 }) {
const tx = new Transaction({ initiator: wallet })
.redeemValue({
value: assetUtxo,
script: script,
script: script as PlutusScript,
datum: datumConstr,
redeemer: redeemer,
redeemer: redeemer as any, // TODO: Investigate why there is type error without casting any
})
.setRequiredSigners([addr])
.sendAssets(
Expand Down
Loading

0 comments on commit 68d466d

Please sign in to comment.