feat: interface for bundlr response
This commit is contained in:
@@ -17,6 +17,16 @@ export type BenchmarkStats = { gatewayCommunication: number; stateEvaluation: nu
|
||||
|
||||
export type SigningFunction = (tx: Transaction) => Promise<void>;
|
||||
|
||||
interface BundlrResponse {
|
||||
id: string;
|
||||
public: string;
|
||||
signature: string;
|
||||
block: number;
|
||||
}
|
||||
export interface BundleInteractionResponse {
|
||||
bundlrResponse: BundlrResponse;
|
||||
originalTxId: string;
|
||||
}
|
||||
/**
|
||||
* Interface describing state for all Evolve-compatible contracts.
|
||||
*/
|
||||
@@ -171,7 +181,7 @@ export interface Contract<State = unknown> extends Source {
|
||||
strict?: boolean;
|
||||
vrf?: boolean;
|
||||
}
|
||||
): Promise<any | null>;
|
||||
): Promise<BundleInteractionResponse | null>;
|
||||
|
||||
/**
|
||||
* Returns the full call tree report the last
|
||||
@@ -243,5 +253,5 @@ export interface Contract<State = unknown> extends Source {
|
||||
* and its transaction to be confirmed by the network.
|
||||
* @param newSrcTxId - result of the {@link save} method call.
|
||||
*/
|
||||
evolve(newSrcTxId: string, useBundler?: boolean): Promise<string | null>;
|
||||
evolve(newSrcTxId: string, useBundler?: boolean): Promise<BundleInteractionResponse | string | null>;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ import {
|
||||
SourceType,
|
||||
Tags,
|
||||
SourceImpl,
|
||||
SourceData
|
||||
SourceData,
|
||||
BundleInteractionResponse
|
||||
} from '@warp';
|
||||
import { TransactionStatusResponse } from 'arweave/node/transactions';
|
||||
import { NetworkInfoInterface } from 'arweave/node/network';
|
||||
@@ -239,7 +240,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
strict: false,
|
||||
vrf: false
|
||||
}
|
||||
): Promise<any | null> {
|
||||
): Promise<BundleInteractionResponse | null> {
|
||||
this.logger.info('Bundle interaction input', input);
|
||||
if (!this.signer) {
|
||||
throw new Error("Wallet not connected. Use 'connect' method first.");
|
||||
@@ -758,7 +759,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
return this;
|
||||
}
|
||||
|
||||
async evolve(newSrcTxId: string, useBundler = false): Promise<string | null> {
|
||||
async evolve(newSrcTxId: string, useBundler = false): Promise<string | BundleInteractionResponse | null> {
|
||||
if (useBundler) {
|
||||
return await this.bundleInteraction<any>({ function: 'evolve', value: newSrcTxId });
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable */
|
||||
import Arweave from 'arweave';
|
||||
import { LoggerFactory, WarpNodeFactory } from '../src';
|
||||
import {BundleInteractionResponse, LoggerFactory, WarpNodeFactory} from '../src';
|
||||
import { TsLogFactory } from '../src/logging/node/TsLogFactory';
|
||||
import path from 'path';
|
||||
import knex from 'knex';
|
||||
@@ -34,7 +34,7 @@ async function main() {
|
||||
useNullAsDefault: true
|
||||
});
|
||||
|
||||
const warp = await WarpNodeFactory.knexCached(arweave, knexConfig);
|
||||
const warp = await WarpNodeFactory.memCached(arweave);
|
||||
|
||||
const wallet: JWKInterface = readJSON('.secrets/33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA.json');
|
||||
|
||||
@@ -42,7 +42,7 @@ async function main() {
|
||||
const initialState = fs.readFileSync(path.join(__dirname, 'data/js/token-pst.json'), 'utf8');
|
||||
|
||||
// case 1 - full deploy, js contract
|
||||
const contractTxId = await warp.createContract.deploy(
|
||||
const {contractTxId, srcTxId} = await warp.createContract.deploy(
|
||||
{
|
||||
wallet,
|
||||
initState: initialState,
|
||||
@@ -52,6 +52,7 @@ async function main() {
|
||||
);
|
||||
|
||||
logger.info('tx id:', contractTxId);
|
||||
logger.info('src tx id:', srcTxId);
|
||||
|
||||
// connecting to a given contract
|
||||
const token = warp
|
||||
@@ -60,16 +61,18 @@ async function main() {
|
||||
// calling "writeInteraction" without connecting to a wallet first will cause a runtime error.
|
||||
.connect(wallet);
|
||||
|
||||
const result = await token.bundleInteraction<any>(
|
||||
const result: BundleInteractionResponse = await token.bundleInteraction<any>(
|
||||
{
|
||||
function: 'vrf'
|
||||
},
|
||||
{ vrf: true }
|
||||
);
|
||||
|
||||
const { state } = await token.readState();
|
||||
console.log(result.bundlrResponse);
|
||||
|
||||
logger.info('State', state.vrf);
|
||||
/*const { state } = await token.readState();
|
||||
|
||||
logger.info('State', state.vrf);*/
|
||||
|
||||
/*const result = await token.writeInteraction({
|
||||
function: "transfer",
|
||||
|
||||
Reference in New Issue
Block a user