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