Skip to content

Commit

Permalink
Fix the dependency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed May 10, 2024
1 parent 5a5743c commit 4ff8f2f
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 20 deletions.
9 changes: 8 additions & 1 deletion packages/web3/src/api/node-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
requestWithLog
} from './types'
import { Api as NodeApi, CallContractFailed, CallContractSucceeded } from './api-alephium'
import { tryGetCallResult } from '../contract'
import {
HexString,
addressFromContractId,
Expand All @@ -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<string> {
const nodeApi = new NodeApi<string>({
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion packages/web3/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import 'cross-fetch/polyfill'
import { node } from '..'
import * as node from '../api/api-alephium'

export function convertHttpResponse<T>(response: { status: number; data: T; error?: { detail: string } }): T {
if (response.error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/codec/contract-output-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/codec/transaction-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 2 additions & 8 deletions packages/web3/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
getDefaultPrimitiveValue,
PrimitiveTypes,
decodeArrayType,
fromApiPrimitiveVal
fromApiPrimitiveVal,
tryGetCallResult
} from '../api'
import { CompileProjectResult } from '../api/api-alephium'
import {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion packages/web3/src/contract/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { web3 } from '..'
import * as web3 from '../global'
import { node } from '../api'
import { Subscription, SubscribeOptions } from '../utils'

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/contract/ralph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/web3/src/signer/tx-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { utils } from '..'
import { binToHex, contractIdFromAddress } from '../utils'
import { fromApiNumber256, node, NodeProvider, toApiNumber256Optional, toApiTokens } from '../api'
import { addressFromPublicKey } from '../utils'
import { toApiDestinations } from './signer'
Expand Down Expand Up @@ -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) }
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/transaction/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { web3 } from '..'
import * as web3 from '../global'
import { node } from '../api'
import { Subscription, SubscribeOptions } from '../utils'

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/utils/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

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'

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
// 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)

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/utils/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

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'
Expand Down

0 comments on commit 4ff8f2f

Please sign in to comment.