Skip to content

Commit

Permalink
Temp Preprod
Browse files Browse the repository at this point in the history
  • Loading branch information
ariady-putra committed Nov 29, 2024
1 parent f6dea92 commit e592f8f
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/[email protected]
- uses: aiken-lang/setup-aiken@v1
with:
version: v1.1.6
version: v1.1.7
- run: aiken fmt --check
- run: aiken c -D
- run: aiken b
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ This showcase project contains 3 validators:
- `dry`
- `withdraw_0`

To run the offchain:
Install `pnpm` if you have not by running `npm i -g pnpm`, and then go to [`offchain`](./offchain):

1. Create a `.env.local` file
2. Run `pnpm dev`
- Run `pnpm i` if you have never run the `offchain`
- Run `pnpm dev` to run the `offchain`

Your `.env.local` file must contain:

```
NEXT_PUBLIC_BF_URL=https://cardano-preprod.blockfrost.io/api/v0
NEXT_PUBLIC_BF_PID=preprodYOUR_PREPROD_BLOCKFROST_PROJECT_ID
NEXT_PUBLIC_CARDANO_NETWORK=Preprod
```

To install `pnpm` run `npm i -g pnpm`.
Open http://localhost:3000

## `owner`

Expand Down
2 changes: 1 addition & 1 deletion aiken.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ariady-putra-emurgo/aiken_staking_validator"
version = "0.0.0"
compiler = "v1.1.6"
compiler = "v1.1.7"
plutus = "v3"
license = "Apache-2.0"
description = "Aiken contracts for project 'ariady-putra-emurgo/aiken_staking_validator'"
Expand Down
10 changes: 3 additions & 7 deletions offchain/app/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ import { useEffect, useState } from "react";
import WalletConnectors from "@/components/WalletConnectors";
import Dashboard from "@/components/Dashboard";

import { Address, Blockfrost, Lucid, LucidEvolution, Network } from "@lucid-evolution/lucid";
import { Address, Lucid, LucidEvolution } from "@lucid-evolution/lucid";
import { network, provider } from "@/config/lucid";
import { Wallet } from "@/types/cardano";

export default function Home() {
const NETWORK = process.env.NEXT_PUBLIC_CARDANO_NETWORK as Network;
const BF_URL = `${process.env.NEXT_PUBLIC_BF_URL}`;
const BF_PID = `${process.env.NEXT_PUBLIC_BF_PID}`;
const BLOCKFROST = new Blockfrost(BF_URL, BF_PID);

const [lucid, setLucid] = useState<LucidEvolution>();
const [address, setAddress] = useState<Address>(""); // Address = string; eg. "addr_..."
const [result, setResult] = useState("");

useEffect(() => {
Lucid(BLOCKFROST, NETWORK).then(setLucid).catch(handleError);
Lucid(provider, network).then(setLucid).catch(handleError);
localStorage.clear();
}, []);

Expand Down
128 changes: 79 additions & 49 deletions offchain/components/Dashboard.tsx

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions offchain/components/actions/OwnerDry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ export default function OwnerDry(props: {

useEffect(() => {
if (!dRepID) return; // skip
fetch(`/governance/dreps/${dRepID}`, { headers: { project_id: `${process.env.NEXT_PUBLIC_BF_PID}` } })
.then((dRep) => dRep.json())
.then(({ hex, has_script }) => {
fetch("/koios/drep_info?select=hex,has_script", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ _drep_ids: [dRepID] }),
})
.then((dReps) => dReps.json())
.then(([{ hex, has_script }]) => {
const credential: Credential = {
type: has_script ? "Script" : "Key",
hash: hex,
Expand Down
23 changes: 14 additions & 9 deletions offchain/components/actions/Withdraw0.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import {
validatorToAddress,
validatorToScriptHash,
} from "@lucid-evolution/lucid";
import { network } from "@/config/lucid";
import * as Script from "@/config/script";
import { SpendValidatorDatumType } from "@/types/withdraw0";
import { Action } from "@/types/action";
import * as Script from "@/types/script";

export default function Withdraw0(props: {
lucid: LucidEvolution;
Expand All @@ -55,10 +56,10 @@ export default function Withdraw0(props: {
const [spendableBy, setSpendableBy] = useState("");

useEffect(() => {
fetch("/blocks/latest", { headers: { project_id: `${process.env.NEXT_PUBLIC_BF_PID}` } })
.then((block) => block.json())
.then(({ time }) => {
const now = IntrDate.fromAbsolute(time * 1_000, localTimeZone);
fetch("/koios/tip?select=block_time")
.then((blocks) => blocks.json())
.then(([{ block_time }]) => {
const now = IntrDate.fromAbsolute(block_time * 1_000, localTimeZone);
setNow(now);

const epochMS = now.toDate().getTime();
Expand Down Expand Up @@ -121,7 +122,7 @@ export default function Withdraw0(props: {
const stakingCredential = scriptHashToCredential(stakingScriptHash);

const spendingValidator: SpendingValidator = { type: "PlutusV3", script };
const validatorAddress = validatorToAddress(lucid.config().network, spendingValidator, stakingCredential);
const validatorAddress = validatorToAddress(network, spendingValidator, stakingCredential);
lucid.utxosAt(validatorAddress).then(setInputUTXOs).catch(onError);
}, []);

Expand Down Expand Up @@ -267,9 +268,13 @@ export default function Withdraw0(props: {

useEffect(() => {
if (!dRepID) return; // skip
fetch(`/governance/dreps/${dRepID}`, { headers: { project_id: `${process.env.NEXT_PUBLIC_BF_PID}` } })
.then((dRep) => dRep.json())
.then(({ hex, has_script }) => {
fetch("/koios/drep_info?select=hex,has_script", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ _drep_ids: [dRepID] }),
})
.then((dReps) => dReps.json())
.then(([{ hex, has_script }]) => {
const credential: Credential = {
type: has_script ? "Script" : "Key",
hash: hex,
Expand Down
4 changes: 4 additions & 0 deletions offchain/config/lucid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Koios, Network, Provider } from "@lucid-evolution/lucid";

export const network: Network = "Preprod";
export const provider: Provider = new Koios("/koios");
File renamed without changes.
12 changes: 2 additions & 10 deletions offchain/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ const nextConfig = {
async rewrites() {
return [
{
source: "/accounts/:path*",
destination: "https://cardano-preprod.blockfrost.io/api/v0/accounts/:path*",
},
{
source: "/blocks/:path*",
destination: "https://cardano-preprod.blockfrost.io/api/v0/blocks/:path*",
},
{
source: "/governance/:path*",
destination: "https://cardano-preprod.blockfrost.io/api/v0/governance/:path*",
source: "/koios/:path*",
destination: "https://preprod.koios.rest/api/v1/:path*",
},
];
},
Expand Down
2 changes: 1 addition & 1 deletion offchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@internationalized/date": "^3.5.6",
"@lucid-evolution/lucid": "^0.4.4",
"@lucid-evolution/lucid": "^0.4.10",
"@nextui-org/accordion": "^2.0.40",
"@nextui-org/button": "2.0.38",
"@nextui-org/code": "2.0.33",
Expand Down
2 changes: 1 addition & 1 deletion plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"plutusVersion": "v3",
"compiler": {
"name": "Aiken",
"version": "v1.1.6+unknown"
"version": "v1.1.7+unknown"
},
"license": "Apache-2.0"
},
Expand Down

0 comments on commit e592f8f

Please sign in to comment.