Skip to content

Commit

Permalink
Merge pull request #353 from MeshJS/yaci-provider-add-admin
Browse files Browse the repository at this point in the history
upgrade yaci provider to include admin endpoints
  • Loading branch information
jinglescode authored Nov 1, 2024
2 parents cfe8d3b + 6710b16 commit e1b03fc
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default function BlockchainProviderKey({
const setMaestroKey = useProviders((state) => state.setMaestroKey);
const yaciUrl = useProviders((state) => state.yaciUrl);
const setYaciUrl = useProviders((state) => state.setYaciUrl);
const yaciAdminUrl = useProviders((state) => state.yaciAdminUrl);
const setYaciAdminUrl = useProviders((state) => state.setYaciAdminUrl);
const ogmiosUrl = useProviders((state) => state.ogmiosUrl);
const setOgmiosUrl = useProviders((state) => state.setOgmiosUrl);
const utxorpc = useProviders((state) => state.utxorpc);
Expand Down Expand Up @@ -125,9 +127,15 @@ export default function BlockchainProviderKey({
<Input
value={yaciUrl}
onChange={(e) => setYaciUrl(e.target.value)}
placeholder="Instance URL"
placeholder="e.g. http://localhost:8080/api/v1/"
label="Instance URL"
type="password"
key={0}
/>,
<Input
value={yaciAdminUrl}
onChange={(e) => setYaciAdminUrl(e.target.value)}
placeholder="e.g. http://localhost:10000"
label="Instance Admin URL"
key={0}
/>,
]}
Expand Down
4 changes: 4 additions & 0 deletions apps/playground/src/hooks/useProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface State {
setKoiosKey: (network: KoiosSupportedNetworks, apiKey: string) => void;
yaciUrl: string;
setYaciUrl: (url: string) => void;
yaciAdminUrl: string;
setYaciAdminUrl: (url: string) => void;
ogmiosUrl: string;
setOgmiosUrl: (url: string) => void;
utxorpc: { url: string; key: string };
Expand All @@ -37,6 +39,8 @@ export const useProviders = create<State>()(
setKoiosKey: (network, apiKey) => set({ koiosKey: { network, apiKey } }),
yaciUrl: "https://yaci-node.meshjs.dev/api/v1/",
setYaciUrl: (url) => set({ yaciUrl: url }),
yaciAdminUrl: "http://localhost:10000/",
setYaciAdminUrl: (url) => set({ yaciAdminUrl: url }),
ogmiosUrl: "",
setOgmiosUrl: (url) => set({ ogmiosUrl: url }),
utxorpc: { url: "http://localhost:50051", key: "api-key" },
Expand Down
77 changes: 77 additions & 0 deletions apps/playground/src/pages/providers/yaci-endpoints/devnet-info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { YaciProvider } from "@meshsdk/core";

import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";
import Codeblock from "~/components/text/codeblock";

export default function YaciDevnetInfo({
yaciProvider,
provider,
}: {
yaciProvider: YaciProvider;
provider: string;
}) {
return (
<TwoColumnsScroll
sidebarTo="getDevnetInfo"
title="Admin Get Devnet Info"
leftSection={Left()}
rightSection={Right(yaciProvider, provider)}
/>
);
}

function Left() {
let code = JSON.stringify(
{
nodePort: 0,
submitApiPort: 0,
socketPath: "string",
protocolMagic: 0,
slotLength: 0,
blockTime: 0,
epochLength: 0,
p2pEnabled: true,
startTime: 0,
masterNode: true,
adminNodeUrl: "string",
era: "Byron",
genesisProfile: "zero_fee",
ogmiosPort: 0,
kupoPort: 0,
yaciStorePort: 0,
socatPort: 0,
prometheusPort: 0,
blockProducer: true,
},
null,
2,
);
return (
<>
<p>Get information about the devnet.</p>
<Codeblock data={`await yaciProvider.getDevnetInfo()`} />
<p>Example response:</p>
<Codeblock data={code} />
</>
);
}

function Right(yaciProvider: YaciProvider, provider: string) {
async function runDemo() {
return await yaciProvider.getDevnetInfo();
}

let code = `await yaciProvider.getDevnetInfo();`;

return (
<LiveCodeDemo
title="Get Devnet Info"
subtitle="Admin function to get devnet info"
runCodeFunction={runDemo}
runDemoShowProviderInit={true}
runDemoProvider={provider}
code={code}
></LiveCodeDemo>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { useState } from "react";

import { YaciProvider } from "@meshsdk/core";

import Input from "~/components/form/input";
import InputTable from "~/components/sections/input-table";
import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";
import Codeblock from "~/components/text/codeblock";

export default function YacigetGenesisByEra({
yaciProvider,
provider,
}: {
yaciProvider: YaciProvider;
provider: string;
}) {
return (
<TwoColumnsScroll
sidebarTo="getGenesisByEra"
title="Admin Get Genesis Info By Era"
leftSection={Left()}
rightSection={Right(yaciProvider, provider)}
/>
);
}

function Left() {
let code = JSON.stringify(
{
activeSlotsCoeff: 1,
epochLength: 500,
genDelegs: {
"337bc5ef0f1abf205624555c13a37258c42b46b1259a6b1a6d82574e": {
delegate: "41fd6bb31f34469320aa47cf6ccc3918e58a06d60ea1f2361efe2458",
vrf: "7053e3ecd2b19db13e5338aa75fb518fc08b6c218f56ad65760d3eb074be95d4",
},
},
initialFunds: {
"60ba957a0fff6816021b2afa7900beea68fd10f2d78fb5b64de0d2379c": 3000000000000000,
"007290ea8fa9433c1045a4c8473959ad608e6c03a58c7de33bdbd3ce6f295b987135610616f3c74e11c94d77b6ced5ccc93a7d719cfb135062": 300000000000,
"605276322ac7882434173dcc6441905f6737689bd309b68ad8b3614fd8": 3000000000000000,
"60a0f1aa7dca95017c11e7e373aebcf0c4568cf47ec12b94f8eb5bba8b": 3000000000000000,
"005867c3b8e27840f556ac268b781578b14c5661fc63ee720dbeab663f9d4dcd7e454d2434164f4efb8edeb358d86a1dad9ec6224cfcbce3e6": 1000000000,
},
maxKESEvolutions: 60,
maxLovelaceSupply: 45000000000000000,
networkId: "Testnet",
networkMagic: 42,
protocolParams: {
a0: 0,
decentralisationParam: 0,
eMax: 18,
extraEntropy: {
tag: "NeutralNonce",
},
keyDeposit: 2000000,
maxBlockBodySize: 65536,
maxBlockHeaderSize: 1100,
maxTxSize: 16384,
minFeeA: 0,
minFeeB: 0,
minPoolCost: 340000000,
minUTxOValue: 1000000,
nOpt: 100,
poolDeposit: 500000000,
protocolVersion: {
major: 8,
minor: 0,
},
rho: 0.003,
tau: 0.2,
},
securityParam: 300,
slotLength: 1,
slotsPerKESPeriod: 129600,
staking: {
pools: {
"7301761068762f5900bde9eb7c1c15b09840285130f5b0f53606cc57": {
cost: 340000000,
margin: 0,
metadata: null,
owners: [],
pledge: 0,
publicKey:
"7301761068762f5900bde9eb7c1c15b09840285130f5b0f53606cc57",
relays: [],
rewardAccount: {
credential: {
keyHash:
"11a14edf73b08a0a27cb98b2c57eb37c780df18fcfcf6785ed5df84a",
},
network: "Testnet",
},
vrf: "c2b62ffa92ad18ffc117ea3abeb161a68885000a466f9c71db5e4731d6630061",
},
},
stake: {
"9d4dcd7e454d2434164f4efb8edeb358d86a1dad9ec6224cfcbce3e6":
"7301761068762f5900bde9eb7c1c15b09840285130f5b0f53606cc57",
},
},
systemStart: "2024-10-30T05:11:07.442512Z",
updateQuorum: 1,
},
null,
2,
);
return (
<>
<p>
You can topup ADA for any address. To topup ADA in your wallet, run the
following command from devnet:
</p>
<Codeblock data={`await yaciProvider.getGenesisByEra(<era>)`} />

<p>Example response:</p>
<Codeblock data={code} />
</>
);
}

function Right(yaciProvider: YaciProvider, provider: string) {
const [userInput, setUserInput] = useState<string>("shelley");
async function runDemo() {
return await yaciProvider.getGenesisByEra(userInput);
}

let code = `await yaciProvider.getGenesisByEra('${userInput}');`;

return (
<LiveCodeDemo
title="Get Genesis Info By Era"
subtitle="Admin function to get genesis info by era"
runCodeFunction={runDemo}
runDemoShowProviderInit={true}
runDemoProvider={provider}
code={code}
>
<InputTable
listInputs={[
<Input
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
placeholder="e.g. shelley"
label="Era"
key={0}
/>,
]}
/>
</LiveCodeDemo>
);
}
24 changes: 24 additions & 0 deletions apps/playground/src/pages/providers/yaci-endpoints/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { YaciProvider } from "@meshsdk/core";

import YaciDevnetInfo from "./devnet-info";
import YacigetGenesisByEra from "./genesis-info-era";
import YaciTopupAddress from "./topup-address";

export default function ProviderYaciEndpoints({
yaciProvider,
provider,
}: {
yaciProvider: YaciProvider;
provider: string;
}) {
return (
<>
<YaciDevnetInfo yaciProvider={yaciProvider} provider={provider} />
<YacigetGenesisByEra
yaciProvider={yaciProvider}
provider={provider}
/>
<YaciTopupAddress yaciProvider={yaciProvider} provider={provider} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useState } from "react";

import { YaciProvider } from "@meshsdk/core";

import Input from "~/components/form/input";
import InputTable from "~/components/sections/input-table";
import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";
import Codeblock from "~/components/text/codeblock";
import { demoAddresses } from "~/data/cardano";

export default function YaciTopupAddress({
yaciProvider,
provider,
}: {
yaciProvider: YaciProvider;
provider: string;
}) {
return (
<TwoColumnsScroll
sidebarTo="addressTopup"
title="Admin Address Topup"
leftSection={Left()}
rightSection={Right(yaciProvider, provider)}
/>
);
}

function Left() {
return (
<>
<p>
You can topup ADA for any address. To topup ADA in your wallet, run the
following command from devnet:
</p>
<Codeblock
data={`await yaciProvider.addressTopup(<address>, <amount>)`}
/>
</>
);
}

function Right(yaciProvider: YaciProvider, provider: string) {
const [userInput, setUserInput] = useState<string>(
demoAddresses.testnetPayment,
);
const [userInput2, setUserInput2] = useState<string>("20000000");

async function runDemo() {
return await yaciProvider.addressTopup(userInput, userInput2);
}

let code = `await yaciProvider.addressTopup('${userInput}', '${userInput2}');`;

return (
<LiveCodeDemo
title="Topup Address"
subtitle="Admin function to topup address with ADA"
runCodeFunction={runDemo}
runDemoShowProviderInit={true}
runDemoProvider={provider}
code={code}
>
<InputTable
listInputs={[
<Input
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
placeholder="Address"
label="Address"
key={0}
/>,
<Input
value={userInput2}
onChange={(e) => setUserInput2(e.target.value)}
placeholder="Amount"
label="Amount"
key={0}
/>,
]}
/>
</LiveCodeDemo>
);
}
Loading

0 comments on commit e1b03fc

Please sign in to comment.