@alephium/web3 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -305,6 +305,6 @@ export declare function subscribeContractEvents(contract: Contract, instance: Co
305
305
  export declare function callMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>, getContractByCodeHash?: (codeHash: string) => Contract): Promise<CallContractResult<R>>;
306
306
  export declare function multicallMethods<I extends ContractInstance, F extends Fields>(contract: ContractFactory<I, F>, instance: ContractInstance, calls: Record<string, Optional<CallContractParams<any>, 'args'>>, getContractByCodeHash?: (codeHash: string) => Contract): Promise<Record<string, CallContractResult<any>>>;
307
307
  export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
308
- export declare const getContractIdFromTxId: (nodeProvider: NodeProvider, txId: string, groupIndex: number) => Promise<HexString>;
309
- export declare const getTokenIdFromTxId: (nodeProvider: NodeProvider, txId: string, groupIndex: number) => Promise<HexString>;
308
+ export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
309
+ export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
310
310
  export {};
@@ -43,7 +43,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
43
43
  return (mod && mod.__esModule) ? mod : { "default": mod };
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.getTokenIdFromTxId = exports.getContractIdFromTxId = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddress = exports.CreateContractEventAddress = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.toApiVals = exports.Script = exports.Contract = exports.Artifact = exports.Project = exports.ProjectArtifact = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
46
+ exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddress = exports.CreateContractEventAddress = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.toApiVals = exports.Script = exports.Contract = exports.Artifact = exports.Project = exports.ProjectArtifact = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
47
47
  const buffer_1 = require("buffer/");
48
48
  const fs_1 = __importDefault(require("fs"));
49
49
  const fs_2 = require("fs");
@@ -1174,16 +1174,13 @@ async function getContractEventsCurrentCount(contractAddress) {
1174
1174
  }
1175
1175
  exports.getContractEventsCurrentCount = getContractEventsCurrentCount;
1176
1176
  // This function only works in the simple case where a single non-subcontract is created in the tx
1177
- const getContractIdFromTxId = async (nodeProvider, txId, groupIndex) => {
1178
- const txDetails = await nodeProvider.transactions.getTransactionsDetailsTxid(txId, {
1179
- fromGroup: groupIndex,
1180
- toGroup: groupIndex
1181
- });
1182
- const outputIndex = txDetails.unsigned.fixedOutputs.length;
1183
- const hex = txId + outputIndex.toString(16).padStart(8, '0');
1177
+ const getContractIdFromUnsignedTx = async (nodeProvider, unsignedTx) => {
1178
+ const result = await nodeProvider.transactions.postTransactionsDecodeUnsignedTx({ unsignedTx });
1179
+ const outputIndex = result.unsignedTx.fixedOutputs.length;
1180
+ const hex = result.unsignedTx.txId + outputIndex.toString(16).padStart(8, '0');
1184
1181
  const hashHex = (0, utils_1.binToHex)(blake.blake2b((0, utils_1.hexToBinUnsafe)(hex), undefined, 32));
1185
- return hashHex.slice(0, 62) + groupIndex.toString(16).padStart(2, '0');
1182
+ return hashHex.slice(0, 62) + result.fromGroup.toString(16).padStart(2, '0');
1186
1183
  };
1187
- exports.getContractIdFromTxId = getContractIdFromTxId;
1184
+ exports.getContractIdFromUnsignedTx = getContractIdFromUnsignedTx;
1188
1185
  // This function only works in the simple case where a single non-subcontract is created in the tx
1189
- exports.getTokenIdFromTxId = exports.getContractIdFromTxId;
1186
+ exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -1798,20 +1798,16 @@ export async function getContractEventsCurrentCount(contractAddress: Address): P
1798
1798
  }
1799
1799
 
1800
1800
  // This function only works in the simple case where a single non-subcontract is created in the tx
1801
- export const getContractIdFromTxId = async (
1801
+ export const getContractIdFromUnsignedTx = async (
1802
1802
  nodeProvider: NodeProvider,
1803
- txId: string,
1804
- groupIndex: number
1803
+ unsignedTx: string
1805
1804
  ): Promise<HexString> => {
1806
- const txDetails = await nodeProvider.transactions.getTransactionsDetailsTxid(txId, {
1807
- fromGroup: groupIndex,
1808
- toGroup: groupIndex
1809
- })
1810
- const outputIndex = txDetails.unsigned.fixedOutputs.length
1811
- const hex = txId + outputIndex.toString(16).padStart(8, '0')
1805
+ const result = await nodeProvider.transactions.postTransactionsDecodeUnsignedTx({ unsignedTx })
1806
+ const outputIndex = result.unsignedTx.fixedOutputs.length
1807
+ const hex = result.unsignedTx.txId + outputIndex.toString(16).padStart(8, '0')
1812
1808
  const hashHex = binToHex(blake.blake2b(hexToBinUnsafe(hex), undefined, 32))
1813
- return hashHex.slice(0, 62) + groupIndex.toString(16).padStart(2, '0')
1809
+ return hashHex.slice(0, 62) + result.fromGroup.toString(16).padStart(2, '0')
1814
1810
  }
1815
1811
 
1816
1812
  // This function only works in the simple case where a single non-subcontract is created in the tx
1817
- export const getTokenIdFromTxId = getContractIdFromTxId
1813
+ export const getTokenIdFromUnsignedTx = getContractIdFromUnsignedTx