Skip to content

Commit

Permalink
Merge pull request #277 from MeshJS/feature/aiken-cli
Browse files Browse the repository at this point in the history
Feature/aiken cli
  • Loading branch information
HinsonSIDAN authored Aug 27, 2024
2 parents 2cf4c48 + 68809b4 commit 10289bd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const emptyTxBuilderBody = (): MeshTxBuilderBody => ({
withdrawals: [],
signingKey: [],
selectionConfig: {
threshold: "5000000",
threshold: "0",
strategy: "experimental",
includeTxFees: true,
},
Expand Down
12 changes: 12 additions & 0 deletions packages/mesh-common/src/utxo-selection/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ export const experimentalSelectUtxos = (
const singletons = new Set<number>();
const pairs = new Set<number>();
const rest = new Set<number>();
const collaterals = new Set<number>();
for (let i = 0; i < inputs.length; i++) {
switch (inputs[i]!.output.amount.length) {
case 1: {
const quantity = inputs[i]!.output.amount[0]?.quantity;
if (quantity == "5000000" || quantity == "10000000") {
collaterals.add(i);
break;
}
onlyLovelace.add(i);
break;
}
Expand Down Expand Up @@ -111,6 +117,12 @@ export const experimentalSelectUtxos = (
addUtxoWithAssetAmount(inputIndex, "lovelace", rest);
}

for (const inputIndex of collaterals) {
const assetRequired = totalRequiredAssets.get("lovelace");
if (!assetRequired || Number(assetRequired) <= 0) break;
addUtxoWithAssetAmount(inputIndex, "lovelace", collaterals);
}

for (const assetUnit of totalRequiredAssets.keys()) {
if (Number(totalRequiredAssets.get(assetUnit)) > 0) {
console.warn("Insufficient funds for", assetUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ platform = "github"
name = "aiken-lang/stdlib"
version = "1.9.0"
source = "github"

[[dependencies]]
name = "sidan-lab/vodka"
version = "0.0.1-beta"
source = "github"
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,57 @@ use aiken/hash.{Blake2b_224, Hash}
use aiken/list
use aiken/transaction.{ScriptContext}
use aiken/transaction/credential.{VerificationKey}

type Datum {
owner: Hash<Blake2b_224, VerificationKey>,
}

type Redeemer {
msg: ByteArray,
}

validator {
fn hello_world(datum: Datum, redeemer: Redeemer, context: ScriptContext) -> Bool {
let must_say_hello =
redeemer.msg == "Hello, World!"

fn hello_world(
datum: Datum,
redeemer: Redeemer,
context: ScriptContext,
) -> Bool {
let must_say_hello = redeemer.msg == "Hello, World!"
let must_be_signed =
list.has(context.transaction.extra_signatories, datum.owner)

must_say_hello && must_be_signed
}
}

fn mock_tx(is_owner_signed: Bool) -> Transaction {
mocktail_tx()
|> required_signer_hash(is_owner_signed, mock_pub_key_hash(0))
|> complete()
}

test test_hello_world() {
let datum = Datum { owner: mock_pub_key_hash(0) }
let redeemer = Redeemer { msg: "Hello, World!" }
let tx = mock_tx(True)
let context =
ScriptContext { transaction: tx, purpose: Spend(mock_utxo_ref(0, 0)) }
hello_world(datum, redeemer, context)
}

test test_failed_hello_world_incorrect_redeemer() {
let datum = Datum { owner: mock_pub_key_hash(0) }
let redeemer = Redeemer { msg: "GM World!" }
let tx = mock_tx(True)
let context =
ScriptContext { transaction: tx, purpose: Spend(mock_utxo_ref(0, 0)) }
!hello_world(datum, redeemer, context)
}

test test_failed_hello_world_without_signer() {
let datum = Datum { owner: mock_pub_key_hash(0) }
let redeemer = Redeemer { msg: "Hello, World!" }
let tx = mock_tx(False)
let context =
ScriptContext { transaction: tx, purpose: Spend(mock_utxo_ref(0, 0)) }
!hello_world(datum, redeemer, context)
}
3 changes: 0 additions & 3 deletions packages/mesh-provider/src/yaci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,6 @@ export class YaciProvider
},
);

console.log("Yaci status", status);
console.log("Yaci data", data);

if (status === 202 && data.result.EvaluationResult) {
const tagMap: { [key: string]: RedeemerTagType } = {
spend: "SPEND",
Expand Down
8 changes: 4 additions & 4 deletions scripts/mesh-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "create-mesh-app",
"name": "mesh",
"description": "A quick and easy way to bootstrap your dApps on Cardano using Mesh.",
"homepage": "https://meshjs.dev",
"author": "MeshJS",
"version": "1.5.1",
"version": "1.5.2",
"license": "Apache-2.0",
"main": "dist/create-mesh-app.cjs.js",
"main": "dist/mesh.cjs.js",
"bin": {
"create-mesh-app": "./bin/create-mesh-app"
"mesh": "./bin/mesh"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 10289bd

Please sign in to comment.