diff --git a/src/common/ar-io.ts b/src/common/ar-io.ts index b6d4e9c3..3c5c6eb4 100644 --- a/src/common/ar-io.ts +++ b/src/common/ar-io.ts @@ -592,7 +592,11 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { qty: number; denomination: DENOMINATIONS; }): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction<{ + target: WalletAddress; + qty: number; + denomination: DENOMINATIONS; + }>({ functionName: AR_IO_CONTRACT_FUNCTIONS.TRANSFER, inputs: { target, @@ -632,7 +636,7 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { async joinNetwork( params: JoinNetworkParams, ): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction({ functionName: AR_IO_CONTRACT_FUNCTIONS.JOIN_NETWORK, inputs: params, signer: this.signer, @@ -651,7 +655,7 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { async updateGatewaySettings( params: UpdateGatewaySettingsParams, ): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction({ functionName: AR_IO_CONTRACT_FUNCTIONS.UPDATE_GATEWAY_SETTINGS, inputs: params, signer: this.signer, @@ -672,7 +676,7 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { target: string; qty: number; }): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction<{ target: string; qty: number }>({ functionName: AR_IO_CONTRACT_FUNCTIONS.DELEGATE_STAKE, inputs: params, signer: this.signer, @@ -693,7 +697,7 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { target: string; qty: number; }): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction<{ target: string; qty: number }>({ functionName: AR_IO_CONTRACT_FUNCTIONS.DECREASE_DELEGATE_STAKE, inputs: params, signer: this.signer, @@ -712,7 +716,7 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { async increaseOperatorStake(params: { qty: number; }): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction<{ qty: number }>({ functionName: AR_IO_CONTRACT_FUNCTIONS.INCREASE_OPERATOR_STAKE, inputs: params, signer: this.signer, @@ -731,7 +735,7 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { async decreaseOperatorStake(params: { qty: number; }): Promise { - const res = this.contract.writeInteraction({ + const res = this.contract.writeInteraction<{ qty: number }>({ functionName: AR_IO_CONTRACT_FUNCTIONS.DECREASE_OPERATOR_STAKE, inputs: params, signer: this.signer, @@ -756,7 +760,10 @@ export class ArIOWritable extends ArIOReadable implements ArIOWriteContract { reportTxId: TransactionId; failedGateways: WalletAddress[]; }): Promise { - return this.contract.writeInteraction({ + return this.contract.writeInteraction<{ + observerReportTxId: TransactionId; + failedGateways: WalletAddress[]; + }>({ functionName: AR_IO_CONTRACT_FUNCTIONS.SAVE_OBSERVATIONS, inputs: { observerReportTxId: params.reportTxId, diff --git a/src/common/arweave.ts b/src/common/arweave.ts index 2d573c29..773fd764 100644 --- a/src/common/arweave.ts +++ b/src/common/arweave.ts @@ -17,7 +17,7 @@ import Arweave from 'arweave'; export const defaultArweave = Arweave.init({ - host: 'arweave.net', + host: 'ar-io.dev', port: 443, protocol: 'https', }); diff --git a/src/common/contracts/warp-contract.ts b/src/common/contracts/warp-contract.ts index 34d3c8f8..ae0f82a0 100644 --- a/src/common/contracts/warp-contract.ts +++ b/src/common/contracts/warp-contract.ts @@ -41,9 +41,7 @@ import { FailedRequestError, WriteInteractionError } from '../error.js'; import { DefaultLogger } from '../logger.js'; import { defaultWarp } from '../warp.js'; -LoggerFactory.INST.setOptions({ - logLevel: 'fatal', -}); +LoggerFactory.INST.logLevel('debug'); export class WarpContract implements BaseContract, ReadContract, WriteContract @@ -89,12 +87,14 @@ export class WarpContract } const warpSigner = new Signature(this.warp, { signer: async (tx: Transaction) => { + const publicKey = await signer.publicKey; const dataToSign = await tx.getSignatureData(); - const signatureBuffer = Buffer.from(await signer.sign(dataToSign)); + const signatureUint8Array = await signer.sign(dataToSign); + const signatureBuffer = Buffer.from(signatureUint8Array); const id = sha256B64Url(signatureBuffer); tx.setSignature({ id: id, - owner: toB64Url(signer.publicKey), + owner: toB64Url(publicKey), signature: toB64Url(signatureBuffer), }); }, @@ -204,15 +204,27 @@ export class WarpContract ); } - const writeResult = await this.contract.writeInteraction({ - function: functionName, - ...inputs, - }); + const writeResult = await this.contract.writeInteraction( + { + function: functionName, + ...inputs, + }, + { + disableBundling: true, + }, + ); if (!writeResult?.interactionTx) { - throw new Error(`Failed to write contract interaction ${functionName}`); + throw new Error( + `Failed to write contract interaction: ${functionName}`, + ); } + this.logger.debug('Successfully wrote contract interaction', { + contractTxId: this.contractTxId, + interactionTxId: writeResult.originalTxId, + }); + return writeResult.interactionTx; } catch (error) { this.logger.error( diff --git a/src/utils/base64.ts b/src/utils/base64.ts index 8b00ac3b..33814b4d 100644 --- a/src/utils/base64.ts +++ b/src/utils/base64.ts @@ -14,22 +14,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import { bufferTob64Url } from 'arweave/node/lib/utils.js'; import { createHash } from 'crypto'; export function fromB64Url(input: string): Buffer { - const paddingLength = input.length % 4 === 0 ? 0 : 4 - (input.length % 4); - - const base64 = input - .replace(/-/g, '+') - .replace(/_/g, '/') - .concat('='.repeat(paddingLength)); - - return Buffer.from(base64, 'base64'); + return Buffer.from(input, 'base64url'); } export function toB64Url(buffer: Buffer): string { - return bufferTob64Url(buffer); + return buffer.toString('base64url'); } export function sha256B64Url(input: Buffer): string { diff --git a/tests/utils.ts b/tests/utils.ts index 9d63a53c..94aefd9a 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -2,7 +2,7 @@ import Arweave from 'arweave'; import { JWKInterface } from 'arweave/node/lib/wallet'; import * as fs from 'fs'; import path from 'path'; -import { ContractDeploy, Warp } from 'warp-contracts'; +import { ContractDeploy, SourceType, Warp } from 'warp-contracts'; import { WeightedObserver } from '../src/contract-state'; @@ -29,11 +29,6 @@ export async function deployANTContract({ ), ); return await warp.deploy({ - evaluationManifest: { - evaluationOptions: { - useKVStorage: true, - }, - }, wallet: jwk, src: src, initState: JSON.stringify({ @@ -42,6 +37,11 @@ export async function deployANTContract({ controllers: [address], balances: { [address]: 1000000 }, }), + evaluationManifest: { + evaluationOptions: { + sourceType: SourceType.ARWEAVE, + }, + }, }); } @@ -93,6 +93,11 @@ export async function deployArIOContract({ 0: updatedPrescribedObservers, }, }), + evaluationManifest: { + evaluationOptions: { + sourceType: SourceType.ARWEAVE, + }, + }, }); }