Skip to content

Commit

Permalink
chore: add readme and more CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Aug 26, 2023
1 parent e830c33 commit d0fc8e0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ jobs:
- run: aiken fmt --check
- run: aiken check
- run: aiken build

- uses: denoland/setup-deno@v1
with:
deno-version: vx.x.x
- run: deno task e2e
11 changes: 7 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
}
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true,
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# Fortuna

Bitcoin style proof of work in smart contract form.

## Mining $TUNA

> The current miner is naive and a better implementation is coming soon.
### Requirements

- [Deno](https://deno.land/[email protected]/getting_started/installation)
- [Kupo](https://cardanosolutions.github.io/kupo/)
- [Ogmios](https://github.com/CardanoSolutions/ogmios)

> You can easily get access to Kupo and Ogmios with
> [Demeter](https://demeter.run). Once you have a project in Demeter you can
> connect Ogmios and Kupo extensions for mainnet. Make sure to toggle
> `Expose http port` in each extensions' settings.
#### Environment variables

Once you have URLs for Kupo and Ogmios, create a `.env` file in the root of the
project with the following content:

```
KUPO_URL="https://<Kupo URL>"
OGMIOS_URL="wss://<Ogmios URL>"
```

#### Wallet

You'll need to create a wallet for the miner which can be done with the
following command:

```sh
deno task cli init
```

Then run the following command to get the miner address:

```sh
deno task cli address
```

You'll need to fund this address with some $ADA to pay for transaction fees.

### Running

After everything is setup, you can run the miner with the following command:

```sh
deno task cli mine
```
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"cli": "deno run --allow-all miner/main.ts",
"e2e": "deno run --allow-all miner/e2e.ts"
}
}
}
2 changes: 1 addition & 1 deletion genesis/preview.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"txHash": "0e1972174c6f0c9a57bb73f82ef2e490071aee921723c571ef507299e255403e",
"index": 1
}
}
}
26 changes: 11 additions & 15 deletions miner/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ const mine = new Command()
`genesis/${preview ? "preview" : "mainnet"}.json`,
);

const {
validator,
validatorHash,
validatorAddress,
}: Genesis = JSON.parse(genesisFile);
const { validator, validatorHash, validatorAddress }: Genesis = JSON.parse(
genesisFile,
);

const provider = new Kupmios(kupoUrl ?? "", ogmiosUrl ?? "");
const lucid = await Lucid.new(provider, preview ? "Preview" : "Mainnet");
Expand All @@ -53,8 +51,8 @@ const mine = new Command()

const validatorUTXOs = await lucid.utxosAt(validatorAddress);

const validatorOutRef = validatorUTXOs.find((u) =>
u.assets[validatorHash + fromText("lord tuna")]
const validatorOutRef = validatorUTXOs.find(
(u) => u.assets[validatorHash + fromText("lord tuna")],
)!;

const validatorState = validatorOutRef.datum!;
Expand Down Expand Up @@ -115,7 +113,7 @@ const mine = new Command()
});

const postDatum = new Constr(0, [
state.fields[0] as bigint + 1n,
(state.fields[0] as bigint) + 1n,
toHex(targetHash),
state.fields[2] as bigint,
state.fields[3] as bigint,
Expand Down Expand Up @@ -253,15 +251,13 @@ const genesis = new Command()
}
});

const init = new Command()
.description("Initialize the miner")
.action(() => {
const seed = generateSeedPhrase();
const init = new Command().description("Initialize the miner").action(() => {
const seed = generateSeedPhrase();

Deno.writeTextFileSync("seed.txt", seed);
Deno.writeTextFileSync("seed.txt", seed);

console.log(`Miner wallet initialized and saved to seed.txt`);
});
console.log(`Miner wallet initialized and saved to seed.txt`);
});

const address = new Command()
.description("Check address balance")
Expand Down

0 comments on commit d0fc8e0

Please sign in to comment.