Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature update/fetcher proposal #444

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions apps/playground/src/pages/providers/fetchers/fetch-proposals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { useState } from "react";

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 { SupportedFetchers } from ".";

export default function FetcherProposalInfo({
blockchainProvider,
provider,
}: {
blockchainProvider: SupportedFetchers;
provider: string;
}) {
const [userInput, setUserInput] = useState<string>(
"372d688faa77e146798b581b322c0f2981a9023764736ade5d12e0e4e796af8c",
);
const [userInput2, setUserInput2] = useState<string>("0");

return (
<TwoColumnsScroll
sidebarTo="fetchProposalInfo"
title="Fetch Proposal Info"
leftSection={Left(userInput, userInput2)}
rightSection={Right(
blockchainProvider,
userInput,
setUserInput,
userInput2,
setUserInput2,
provider,
)}
/>
);
}

function Left(userInput: string, userInput2: string) {
return (
<>
<p>
Get information for a given governance proposal, identified by the
txHash and proposal index
</p>
<Codeblock
data={`await blockchainProvider.fetchGovernanceProposal('${userInput}', ${userInput2})`}
/>
</>
);
}

function Right(
blockchainProvider: SupportedFetchers,
userInput: string,
setUserInput: (value: string) => void,
userInput2: string,
setUserInput2: (value: string) => void,
provider: string,
) {
async function runDemo() {
return await blockchainProvider.fetchGovernanceProposal(
userInput,
Number(userInput2),
);
}

return (
<LiveCodeDemo
title="Fetch Proposals"
subtitle="Fetch Proposals for a given TxHash and certIndex"
runCodeFunction={runDemo}
runDemoShowProviderInit={true}
runDemoProvider={provider}
>
<InputTable
listInputs={[
<Input
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
placeholder="TxHash"
label="TxHash"
key={0}
/>,
<Input
value={userInput2}
onChange={(e) => setUserInput2(e.target.value)}
placeholder="e.g. 0"
label="CertIndex"
key={1}
/>,
]}
/>
</LiveCodeDemo>
);
}
9 changes: 7 additions & 2 deletions apps/playground/src/pages/providers/fetchers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
BlockfrostProvider,
KoiosProvider,
MaestroProvider,
OfflineFetcher,
U5CProvider,
YaciProvider,
OfflineFetcher
} from "@meshsdk/core";

import FetcherAccountInfo from "./fetch-account-info";
Expand All @@ -16,10 +16,11 @@ import FetcherBlockInfo from "./fetch-block-info";
import FetcherCollectionAssets from "./fetch-collection-assets";
import FetcherHandle from "./fetch-handle";
import FetcherHandleAddress from "./fetch-handle-address";
import FetcherProposalInfo from "./fetch-proposals";
import FetcherProtocolParameters from "./fetch-protocol-parameters";
import FetcherTransactionInfo from "./fetch-transaction-info";
import FetcherGet from "./get";
import FetcherUtxos from "./fetch-utxos";
import FetcherGet from "./get";

export default function ProviderFetchers({
blockchainProvider,
Expand Down Expand Up @@ -80,6 +81,10 @@ export default function ProviderFetchers({
blockchainProvider={blockchainProvider}
provider={provider}
/>
<FetcherProposalInfo
blockchainProvider={blockchainProvider}
provider={provider}
/>
</>
);
}
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/mesh-common/src/data/mesh/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const mPubKeyAddress = (
bytes: string,
stakeCredential?: string,
isStakeScriptCredential = false,
): Data =>
): MPubKeyAddress =>
mConStr0([
{ alternative: 0, fields: [bytes] },
mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential),
Expand All @@ -70,7 +70,7 @@ export const mScriptAddress = (
bytes: string,
stakeCredential?: string,
isStakeScriptCredential = false,
): Data =>
): MScriptAddress =>
mConStr0([
{ alternative: 1, fields: [bytes] },
mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential),
Expand Down
5 changes: 5 additions & 0 deletions packages/mesh-common/src/interfaces/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
TransactionInfo,
UTxO,
} from "../types";
import { GovernanceProposalInfo } from "../types/governance";

/**
* Fetcher interface defines end points to query blockchain data.
Expand All @@ -28,5 +29,9 @@ export interface IFetcher {
fetchProtocolParameters(epoch: number): Promise<Protocol>;
fetchTxInfo(hash: string): Promise<TransactionInfo>;
fetchUTxOs(hash: string, index?: number): Promise<UTxO[]>;
fetchGovernanceProposal(
txHash: string,
certIndex: number,
): Promise<GovernanceProposalInfo>;
get(url: string): Promise<any>;
}
14 changes: 14 additions & 0 deletions packages/mesh-common/src/types/governance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type GovernanceProposalInfo = {
txHash: string;
certIndex: number;
governanceType: string;
deposit: number;
returnAddress: string;
governanceDescription: string;
ratifiedEpoch: number;
enactedEpoch: number;
droppedEpoch: number;
expiredEpoch: number;
expiration: number;
metadata: object;
};
1 change: 1 addition & 0 deletions packages/mesh-common/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from "./wallet";
export * from "./transaction-builder";
export * from "./deserialized";
export * from "./blueprint";
export * from "./governance";
34 changes: 34 additions & 0 deletions packages/mesh-provider/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BlockInfo,
castProtocol,
fromUTF8,
GovernanceProposalInfo,
IEvaluator,
IFetcher,
IListener,
Expand Down Expand Up @@ -507,6 +508,39 @@ export class BlockfrostProvider
}
}

async fetchGovernanceProposal(
txHash: string,
certIndex: number,
): Promise<GovernanceProposalInfo> {
try {
const { data, status } = await this._axiosInstance.get(
`governance/proposals/${txHash}/${certIndex}`,
);
if (status === 200 || status == 202)
return <GovernanceProposalInfo>{
txHash: data.tx_hash,
certIndex: data.cert_index,
governanceType: data.governance_type,
deposit: data.deposit,
returnAddress: data.return_address,
governanceDescription: data.governance_description,
ratifiedEpoch: data.ratified_epoch,
enactedEpoch: data.enacted_epoch,
droppedEpoch: data.dropped_epoch,
expiredEpoch: data.expired_epoch,
expiration: data.expiration,
metadata: (
await this._axiosInstance.get(
`governance/proposals/${txHash}/${certIndex}/metadata`,
)
).data,
};
throw parseHttpError(data);
} catch (error) {
throw parseHttpError(error);
}
}

/**
* A generic method to fetch data from a URL.
* @param url - The URL to fetch data from
Expand Down
5 changes: 5 additions & 0 deletions packages/mesh-provider/src/koios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BlockInfo,
castProtocol,
fromUTF8,
GovernanceProposalInfo,
IFetcher,
IListener,
ISubmitter,
Expand Down Expand Up @@ -385,6 +386,10 @@ export class KoiosProvider implements IFetcher, IListener, ISubmitter {
}
}

async fetchGovernanceProposal(txHash: string, certIndex: number): Promise<GovernanceProposalInfo> {
throw new Error("Method not implemented");
}

/**
* A generic method to fetch data from a URL.
* @param url - The URL to fetch data from
Expand Down
5 changes: 5 additions & 0 deletions packages/mesh-provider/src/maestro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BlockInfo,
castProtocol,
fromUTF8,
GovernanceProposalInfo,
IEvaluator,
IFetcher,
IListener,
Expand Down Expand Up @@ -442,6 +443,10 @@ export class MaestroProvider
}
}

async fetchGovernanceProposal(txHash: string, certIndex: number): Promise<GovernanceProposalInfo> {
throw new Error("Method not implemented by Maestro");
}

async get(url: string): Promise<any> {
try {
const { data, status } = await this._axiosInstance.get(url);
Expand Down
4 changes: 4 additions & 0 deletions packages/mesh-provider/src/offline/offline-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ export class OfflineFetcher implements IFetcher {
return utxos;
}

async fetchGovernanceProposal(txHash: string, certIndex: number): Promise<any> {
throw new Error("Method not implemented");
}

/**
* HTTP GET method required by IFetcher interface but not implemented in OfflineFetcher.
* @param url - URL to fetch from
Expand Down
5 changes: 5 additions & 0 deletions packages/mesh-provider/src/utxo-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BlockInfo,
bytesToHex,
castProtocol,
GovernanceProposalInfo,
hexToBytes,
IEvaluator,
IFetcher,
Expand Down Expand Up @@ -317,6 +318,10 @@ export class U5CProvider
throw new Error("Method not implemented.");
}

async fetchGovernanceProposal(txHash: string, certIndex: number): Promise<GovernanceProposalInfo> {
throw new Error("Method not implemented");
}

get(url: string): Promise<any> {
throw new Error("Method not implemented.");
}
Expand Down
12 changes: 10 additions & 2 deletions packages/mesh-provider/src/yaci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BlockInfo,
castProtocol,
fromUTF8,
GovernanceProposalInfo,
IEvaluator,
IFetcher,
IListener,
Expand All @@ -24,7 +25,7 @@ import {
import {
normalizePlutusScript,
resolveRewardAddress,
toScriptRef
toScriptRef,
} from "@meshsdk/core-cst";

import { utxosToAssets } from "./common/utxos-to-assets";
Expand Down Expand Up @@ -104,7 +105,7 @@ export class YaciProvider
const normalized = normalizePlutusScript(plutusScript, "DoubleCBOR");
script = <PlutusScript>{
version: data.type.replace("plutus", ""),
code: normalized
code: normalized,
};
} else {
script = await this.fetchNativeScriptJSON(scriptHash);
Expand Down Expand Up @@ -384,6 +385,13 @@ export class YaciProvider
}
}

async fetchGovernanceProposal(
txHash: string,
certIndex: number,
): Promise<GovernanceProposalInfo> {
throw new Error("Method not implemented by Maestro");
}

async get(url: string): Promise<any> {
try {
const { data, status } = await this._axiosInstance.get(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1469,15 +1469,15 @@ export class MeshTxBuilderCore {
return this;
};

/**
/**
* Sets a specific fee for the transaction to use
* @param fee The specified fee
* @returns The MeshTxBuilder instance
*/
setFee = (fee: string) => {
this.meshTxBuilderBody.fee = fee;
return this;
}
};

/**
* Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
Expand Down
Loading