From 4ff8f2f7f35f969681d4284d37e58e3e73b1a439 Mon Sep 17 00:00:00 2001 From: lbqds Date: Sat, 11 May 2024 07:24:06 +0800 Subject: [PATCH] Fix the dependency issue --- packages/web3/src/api/node-provider.ts | 9 ++++++++- packages/web3/src/api/utils.ts | 2 +- packages/web3/src/codec/contract-output-codec.ts | 2 +- packages/web3/src/codec/transaction-codec.ts | 2 +- packages/web3/src/contract/contract.ts | 10 ++-------- packages/web3/src/contract/events.ts | 2 +- packages/web3/src/contract/ralph.test.ts | 2 +- packages/web3/src/signer/tx-builder.ts | 4 ++-- packages/web3/src/transaction/status.ts | 2 +- packages/web3/src/utils/exchange.ts | 2 +- packages/web3/src/utils/number.ts | 2 +- packages/web3/src/utils/sign.ts | 2 +- 12 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/web3/src/api/node-provider.ts b/packages/web3/src/api/node-provider.ts index e6b23fe16..935c27568 100644 --- a/packages/web3/src/api/node-provider.ts +++ b/packages/web3/src/api/node-provider.ts @@ -28,7 +28,6 @@ import { requestWithLog } from './types' import { Api as NodeApi, CallContractFailed, CallContractSucceeded } from './api-alephium' -import { tryGetCallResult } from '../contract' import { HexString, addressFromContractId, @@ -38,6 +37,7 @@ import { isHexString, toNonNegativeBigInt } from '../utils' +import * as node from '../api/api-alephium' function initializeNodeApi(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): NodeApi { const nodeApi = new NodeApi({ @@ -253,3 +253,10 @@ export class NodeProvider implements NodeProviderApis { } } } + +export function tryGetCallResult(result: node.CallContractResult): node.CallContractSucceeded { + if (result.type === 'CallContractFailed') { + throw new Error(`Failed to call contract, error: ${(result as node.CallContractFailed).error}`) + } + return result as node.CallContractSucceeded +} diff --git a/packages/web3/src/api/utils.ts b/packages/web3/src/api/utils.ts index 88cb848ff..30b7be173 100644 --- a/packages/web3/src/api/utils.ts +++ b/packages/web3/src/api/utils.ts @@ -17,7 +17,7 @@ along with the library. If not, see . */ import 'cross-fetch/polyfill' -import { node } from '..' +import * as node from '../api/api-alephium' export function convertHttpResponse(response: { status: number; data: T; error?: { detail: string } }): T { if (response.error) { diff --git a/packages/web3/src/codec/contract-output-codec.ts b/packages/web3/src/codec/contract-output-codec.ts index dcf86c970..ab75420b3 100644 --- a/packages/web3/src/codec/contract-output-codec.ts +++ b/packages/web3/src/codec/contract-output-codec.ts @@ -24,7 +24,7 @@ import { Codec } from './codec' import { Token, tokensCodec } from './token-codec' import { ContractOutput as ApiContractOutput } from '../api/api-alephium' import { blakeHash, createHint } from './hash' -import { binToHex, bs58 } from '..' +import { binToHex, bs58 } from '../utils' import { signedIntCodec } from './signed-int-codec' import { lockupScriptCodec } from './lockup-script-codec' diff --git a/packages/web3/src/codec/transaction-codec.ts b/packages/web3/src/codec/transaction-codec.ts index d48790a0f..4acc2d36e 100644 --- a/packages/web3/src/codec/transaction-codec.ts +++ b/packages/web3/src/codec/transaction-codec.ts @@ -27,7 +27,7 @@ import { Either } from './either-codec' import { AssetOutput, AssetOutputCodec } from './asset-output-codec' import { ContractOutput, ContractOutputCodec } from './contract-output-codec' import { FixedAssetOutput, Transaction as ApiTransaction } from '../api/api-alephium' -import { hexToBinUnsafe } from '..' +import { hexToBinUnsafe } from '../utils' import { ContractOutput as ApiContractOutput } from '../api/api-alephium' import { Codec } from './codec' import { Output, outputCodec, outputsCodec } from './output-codec' diff --git a/packages/web3/src/contract/contract.ts b/packages/web3/src/contract/contract.ts index 0cb6b37b5..ff9bf9e33 100644 --- a/packages/web3/src/contract/contract.ts +++ b/packages/web3/src/contract/contract.ts @@ -34,7 +34,8 @@ import { getDefaultPrimitiveValue, PrimitiveTypes, decodeArrayType, - fromApiPrimitiveVal + fromApiPrimitiveVal, + tryGetCallResult } from '../api' import { CompileProjectResult } from '../api/api-alephium' import { @@ -2369,10 +2370,3 @@ export const getContractIdFromUnsignedTx = async ( // This function only works in the simple case where a single non-subcontract is created in the tx export const getTokenIdFromUnsignedTx = getContractIdFromUnsignedTx - -export function tryGetCallResult(result: node.CallContractResult): node.CallContractSucceeded { - if (result.type === 'CallContractFailed') { - throw new Error(`Failed to call contract, error: ${(result as node.CallContractFailed).error}`) - } - return result as node.CallContractSucceeded -} diff --git a/packages/web3/src/contract/events.ts b/packages/web3/src/contract/events.ts index 976006dd5..5513eca61 100644 --- a/packages/web3/src/contract/events.ts +++ b/packages/web3/src/contract/events.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License along with the library. If not, see . */ -import { web3 } from '..' +import * as web3 from '../global' import { node } from '../api' import { Subscription, SubscribeOptions } from '../utils' diff --git a/packages/web3/src/contract/ralph.test.ts b/packages/web3/src/contract/ralph.test.ts index 3d535a787..1ac32f46e 100644 --- a/packages/web3/src/contract/ralph.test.ts +++ b/packages/web3/src/contract/ralph.test.ts @@ -19,7 +19,7 @@ along with the library. If not, see . import * as ralph from './ralph' import * as utils from '../utils' import { Fields, FieldsSig, Struct, fromApiArray, fromApiEventFields, fromApiFields, getDefaultValue } from './contract' -import { node } from '..' +import * as node from '../api/api-alephium' describe('contract', function () { it('should encode I256', () => { diff --git a/packages/web3/src/signer/tx-builder.ts b/packages/web3/src/signer/tx-builder.ts index df108870b..e04fdde85 100644 --- a/packages/web3/src/signer/tx-builder.ts +++ b/packages/web3/src/signer/tx-builder.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License along with the library. If not, see . */ -import { utils } from '..' +import { binToHex, contractIdFromAddress } from '../utils' import { fromApiNumber256, node, NodeProvider, toApiNumber256Optional, toApiTokens } from '../api' import { addressFromPublicKey } from '../utils' import { toApiDestinations } from './signer' @@ -90,7 +90,7 @@ export abstract class TransactionBuilder { ...rest } const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data) - const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress)) + const contractId = binToHex(contractIdFromAddress(response.contractAddress)) return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: fromApiNumber256(response.gasPrice) } } diff --git a/packages/web3/src/transaction/status.ts b/packages/web3/src/transaction/status.ts index b0e38ee72..24a54217e 100644 --- a/packages/web3/src/transaction/status.ts +++ b/packages/web3/src/transaction/status.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License along with the library. If not, see . */ -import { web3 } from '..' +import * as web3 from '../global' import { node } from '../api' import { Subscription, SubscribeOptions } from '../utils' diff --git a/packages/web3/src/utils/exchange.ts b/packages/web3/src/utils/exchange.ts index 58ccb4de3..8e45f2e77 100644 --- a/packages/web3/src/utils/exchange.ts +++ b/packages/web3/src/utils/exchange.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License along with the library. If not, see . */ -import { AddressType, addressFromPublicKey, addressFromScript, binToHex, bs58, hexToBinUnsafe } from '..' +import { AddressType, addressFromPublicKey, addressFromScript, binToHex, bs58, hexToBinUnsafe } from '../utils' import { Transaction } from '../api/api-alephium' import { Address } from '../signer' diff --git a/packages/web3/src/utils/number.ts b/packages/web3/src/utils/number.ts index ae196c87a..6de41cf31 100644 --- a/packages/web3/src/utils/number.ts +++ b/packages/web3/src/utils/number.ts @@ -21,7 +21,7 @@ along with the library. If not, see . // 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts import BigNumber from 'bignumber.js' -import { Number256 } from '..' +import { Number256 } from '../api/types' export const isNumeric = (numToCheck: any): boolean => !isNaN(parseFloat(numToCheck)) && isFinite(numToCheck) diff --git a/packages/web3/src/utils/sign.ts b/packages/web3/src/utils/sign.ts index d1a979175..14706d6d6 100644 --- a/packages/web3/src/utils/sign.ts +++ b/packages/web3/src/utils/sign.ts @@ -17,7 +17,7 @@ along with the library. If not, see . */ import { ec as EC } from 'elliptic' -import { binToHex, encodeSignature, hexToBinUnsafe, signatureDecode } from '..' +import { binToHex, encodeSignature, hexToBinUnsafe, signatureDecode } from '../utils' import { KeyType } from '../signer' import * as necc from '@noble/secp256k1' import { createHash, createHmac } from 'crypto'