Skip to content

Commit

Permalink
Merge branch 'remove-get-collection-id' into test-remove-get-collecti…
Browse files Browse the repository at this point in the history
…on-id
  • Loading branch information
h0ngcha0 committed Aug 17, 2023
2 parents 8e728dc + 8c108d2 commit 1592f5f
Show file tree
Hide file tree
Showing 30 changed files with 71 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"fullNodeVersion": "v2.3.5",
"fullNodeVersion": "v2.5.0",
"compilerOptionsUsed": {
"ignoreUnusedConstantsWarnings": false,
"ignoreUnusedVariablesWarnings": false,
Expand Down
2 changes: 1 addition & 1 deletion artifacts/add/Add.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Add",
"bytecode": "02040d4036405740600100020402041600160100010200000202021605160016015f06160016015fa00016002a16012aa100a000160016010e0dce0001000201030404000b160313c40de0b6b3a7640000a2160116021401001600130164c1180102010100021600b0",
"codeHash": "2b9e382c20b4facf21eb745a46a72447dae221c274518e19c60b5ddfe478cc9c",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/add/DestroyAdd.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "DestroyAdd",
"bytecodeTemplate": "01010300000005{1}0d0c{0}0103",
"fieldsSig": {
Expand Down
2 changes: 1 addition & 1 deletion artifacts/add/Main.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Main",
"bytecodeTemplate": "0101030001000a{0}17000e0d0e0e160001001818",
"fieldsSig": {
Expand Down
2 changes: 1 addition & 1 deletion artifacts/greeter/Greeter.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Greeter",
"bytecode": "01010c010000000105030c7bce0002",
"codeHash": "d8a1c2190c6c54f720608a4b264d1c648a9865e0744e942e489c87e64d4e596a",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/greeter/GreeterMain.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "GreeterMain",
"bytecodeTemplate": "01010300020014{0}17000c0d160001000d2f0c7b{0}17010c0d160101000d2f0c7b",
"fieldsSig": {
Expand Down
2 changes: 1 addition & 1 deletion artifacts/nft/MintNFTTest.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "MintNFTTest",
"bytecodeTemplate": "0101030001000b{0}1700b413c40de0b6b3a7640000a2{1}0d0d1600010318",
"fieldsSig": {
Expand Down
2 changes: 1 addition & 1 deletion artifacts/nft/NFTCollectionTest.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "NFTCollectionTest",
"bytecode": "04040912402d406f010000000102ce0102010000000102a0000201000102010f16000001310c7b160040cb17011601c50d7b16010201030105011cb4170116001406414c5048000313026413006417031702160113c40de0b6b3a7640000a2a00040ce00160216030d1601c91704a0000d2aa100160402",
"codeHash": "62a74b8496ee1693de16f2d67d5b3ba3273e3a04cb59aec3a24c1ae5a51c2e0c",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/nft/NFTTest.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "NFTTest",
"bytecode": "020109010000000102ce0002",
"codeHash": "c654f89a813259b6e270c8cf609200907f0824755bb394b00d8b151c3fddf95f",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/sub/Sub.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Sub",
"bytecode": "01011901000202010c05160016015fa00016002a16012ba100a00002",
"codeHash": "513645f5c95a28d55a51070f3d5c51edbda05a98f46b23cad59952e2ee4846a1",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/test/Assert.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Assert",
"bytecode": "00010b0100000000050d0e2f0f7b",
"codeHash": "5bd05924fb9a23ea105df065a8c2dfa463b9ee53cc14a60320140d19dd6151ca",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/test/Debug.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Debug",
"bytecode": "000106010000000000",
"codeHash": "928360bf58942dd1fdd8d197e0e2ef59ecddbf71a6e8fe25d2c0665274f80ce3",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/test/MetaData.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "MetaData",
"bytecode": "0003144027402e010300000005b4b413c40de0b6b3a7640000a702000200000004b213c40de0b6b3a7640000a90200000000000102",
"codeHash": "cade0de390b8e15960b263ac35aa013cb84f844bce6e3e53e6bfe2cc9166623f",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/test/Warnings.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "Warnings",
"bytecode": "02010701000202000102",
"codeHash": "9a0c90d67d729a478062d6794cf7b75c27483c50f6fe2ad13c5ed8873ad1fde2",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/token/FakeTokenTest.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "FakeTokenTest",
"bytecode": "010509121b4024402a010000000103044d18010000000103044d18010000000103044d18010000000103044d18010000000000",
"codeHash": "88d74dcc19bfd075e97c90ab5f48d374f9ff982133d8257d4efc32305c5885b3",
Expand Down
2 changes: 1 addition & 1 deletion artifacts/token/TokenTest.ral.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.3.5",
"version": "v2.5.0",
"name": "TokenTest",
"bytecode": "050409121b4024010000000102ce0002010000000102ce0102010000000102ce0202010000000102ce0302",
"codeHash": "a2800413eb2c5c23d48068db23df5f8eeaba04653e12c8ed59d589720d96dadd",
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
condition: service_healthy

alephium:
image: alephium/dev-alephium:2.3.5
image: alephium/dev-alephium:2.5.0
restart: unless-stopped
ports:
- 19973:19973/tcp
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Configuration<Settings = unknown> {
}

export const DEFAULT_CONFIGURATION_VALUES = {
nodeVersion: '2.3.5',
nodeVersion: '2.5.0',
nodeConfigFile: 'devnet-user.conf',
sourceDir: Project.DEFAULT_CONTRACTS_DIR,
artifactDir: Project.DEFAULT_ARTIFACTS_DIR,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/templates/react/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = function override(config) {
Object.assign(fallback, {
fs: false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify')
stream: require.resolve('stream-browserify'),
path: require.resolve('path-browserify')
})
config.resolve.fallback = fallback
config.plugins = (config.plugins || []).concat([
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject",
"lint": "eslint . --ext ts",
"lint": "eslint . --ext ts,tsx",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\""
},
"eslintConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react'
import './App.css'

import { ExplorerProvider, Contract, Script } from '@alephium/web3'
import contractJson from './artifacts/greeter.ral.json'
import scriptJson from './artifacts/greeter_main.ral.json'
import contractJson from './artifacts/Greeter.ral.json'
import scriptJson from './artifacts/GreeterMain.ral.json'

function Dashboard() {
const api = new ExplorerProvider('https://mainnet-backend.alephium.org')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.0.4",
"version": "v2.5.0",
"name": "Greeter",
"bytecode": "01010c010000000105030c7bce0002",
"codeHash": "d8a1c2190c6c54f720608a4b264d1c648a9865e0744e942e489c87e64d4e596a",
Expand Down Expand Up @@ -28,5 +28,7 @@
"U256"
]
}
]
],
"constants": [],
"enums": []
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.0.4",
"version": "v2.5.0",
"name": "GreeterMain",
"bytecodeTemplate": "01010300020014{0}17000c0d160001000d2f0c7b{0}17010c0d160101000d2f0c7b",
"fieldsSig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/templates/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"outDir": "dist",
"jsx": "react-jsx",
"target": "es2020",
"allowJs": true,
"esModuleInterop": true,
Expand All @@ -16,5 +17,5 @@
"noImplicitOverride": true
},
"exclude": ["node_modules"],
"include": ["src/**/*.ts", "test/**/*.ts", "scripts/**/*.ts", "alephium.config.ts", "artifacts/**/*.ts"]
"include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "scripts/**/*.ts", "alephium.config.ts", "artifacts/**/*.ts"]
}
8 changes: 4 additions & 4 deletions packages/web3-react/src/hooks/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ 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 { useMemo } from 'react'
import { AlephiumConnectContextValue, useAlephiumConnectContext } from '../contexts/alephiumConnect'
import { NodeProvider, SignerProvider } from '@alephium/web3'
import { useAlephiumConnectContext } from '../contexts/alephiumConnect'
import { NodeProvider, SignerProvider, Account, NetworkId } from '@alephium/web3'

export interface Wallet {
signer: SignerProvider
account: AlephiumConnectContextValue['account']
account: Account & { network: NetworkId }
nodeProvider?: NodeProvider
}

export function useWallet() {
const { account, signerProvider } = useAlephiumConnectContext()

return useMemo(() => {
return useMemo<Wallet | undefined>(() => {
if (account !== undefined && signerProvider !== undefined) {
return {
signer: signerProvider,
Expand Down
2 changes: 1 addition & 1 deletion packages/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"author": "Alephium dev <[email protected]>",
"config": {
"alephium_version": "2.3.5",
"alephium_version": "2.5.0",
"explorer_backend_version": "1.15.1"
},
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions packages/web3/src/api/api-alephium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,22 @@ export interface CallContract {
inputAssets?: TestInputAsset[]
}

export interface CallContractResult {
export interface CallContractFailed {
error: string
type: string
}

export type CallContractResult = CallContractFailed | CallContractSucceeded

export interface CallContractSucceeded {
returns: Val[]
/** @format int32 */
gasUsed: number
contracts: ContractState[]
txInputs: string[]
txOutputs: Output[]
events: ContractEventByTxId[]
type: string
}

export interface ChainInfo {
Expand Down Expand Up @@ -1228,7 +1236,7 @@ export class HttpClient<SecurityDataType = unknown> {

/**
* @title Alephium API
* @version 2.3.5
* @version 2.5.0
* @baseUrl ../
*/
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
Expand Down
18 changes: 10 additions & 8 deletions packages/web3/src/api/node-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
StdInterfaceIds
} from './types'
import { Api as NodeApi } from './api-alephium'
import { HexString } from '../contract'
import { HexString, tryGetCallResult } from '../contract'
import { addressFromContractId, addressFromTokenId, groupOfAddress, hexToString } from '../utils'

function initializeNodeApi(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): NodeApi<string> {
Expand Down Expand Up @@ -116,11 +116,12 @@ export class NodeProvider implements NodeProviderApis {
const result = await this.contracts.postContractsMulticallContract({
calls: calls
})
const callResults = result.results.map((r) => tryGetCallResult(r))
return {
symbol: result.results[0].returns[0].value as any as string,
name: result.results[1].returns[0].value as any as string,
decimals: Number(result.results[2].returns[0].value as any as string),
totalSupply: BigInt(result.results[3].returns[0].value as any as string)
symbol: callResults[0].returns[0].value as any as string,
name: callResults[1].returns[0].value as any as string,
decimals: Number(callResults[2].returns[0].value as any as string),
totalSupply: BigInt(callResults[3].returns[0].value as any as string)
}
}

Expand All @@ -130,7 +131,7 @@ export class NodeProvider implements NodeProviderApis {
const group = groupOfAddress(address)
const result = await this.contracts.postContractsCallContract({ methodIndex: 0, group, address })
return {
tokenUri: hexToString(result.returns[0].value as any as string)
tokenUri: hexToString(tryGetCallResult(result).returns[0].value as any as string)
}
}

Expand All @@ -140,9 +141,10 @@ export class NodeProvider implements NodeProviderApis {
const group = groupOfAddress(address)
const calls = Array.from([0, 1], (index) => ({ methodIndex: index, group: group, address: address }))
const result = await this.contracts.postContractsMulticallContract({ calls })
const callResults = result.results.map((r) => tryGetCallResult(r))
return {
collectionUri: hexToString(result.results[0].returns[0].value as any as string),
totalSupply: BigInt(result.results[1].returns[0].value as any as string)
collectionUri: hexToString(callResults[0].returns[0].value as any as string),
totalSupply: BigInt(callResults[1].returns[0].value as any as string)
}
}

Expand Down
22 changes: 15 additions & 7 deletions packages/web3/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,18 +1088,19 @@ export class Contract extends Artifact {
getContractByCodeHash?: (codeHash: string) => Contract
): CallContractResult<unknown> {
const returnTypes = this.functions[`${methodIndex}`].returnTypes
const rawReturn = fromApiArray(result.returns, returnTypes)
const callResult = tryGetCallResult(result)
const rawReturn = fromApiArray(callResult.returns, returnTypes)
const returns = rawReturn.length === 0 ? null : rawReturn.length === 1 ? rawReturn[0] : rawReturn

const addressToCodeHash = new Map<string, string>()
result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash))
callResult.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash))
return {
returns: returns,
gasUsed: result.gasUsed,
contracts: result.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
txInputs: result.txInputs,
txOutputs: result.txOutputs.map((output) => fromApiOutput(output)),
events: Contract.fromApiEvents(result.events, addressToCodeHash, txId, getContractByCodeHash)
gasUsed: callResult.gasUsed,
contracts: callResult.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
txInputs: callResult.txInputs,
txOutputs: callResult.txOutputs.map((output) => fromApiOutput(output)),
events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash)
}
}
}
Expand Down Expand Up @@ -1811,3 +1812,10 @@ 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/token/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ describe('nft', function () {

const invalidUri = 'https://ipfs.io/ipfs/invalid'
expect(async () => await validateNFTBaseUri(invalidUri, 2)).rejects.toThrow(Error)
})
}, 10000)
})

0 comments on commit 1592f5f

Please sign in to comment.