From 9d45fa54fe982edf2e2c48c7ab791c4a4de1aaa4 Mon Sep 17 00:00:00 2001 From: Alex Kit Date: Thu, 23 Nov 2023 12:08:29 +0100 Subject: [PATCH] 'bump' --- lib/0xweb.js | 242 +++++++++++++++++++++++++++++++++++++++++++++++---- lib/cli.js | 242 +++++++++++++++++++++++++++++++++++++++++++++++---- package.json | 2 +- 3 files changed, 449 insertions(+), 37 deletions(-) diff --git a/lib/0xweb.js b/lib/0xweb.js index a7b5ca7..841b388 100644 --- a/lib/0xweb.js +++ b/lib/0xweb.js @@ -13224,10 +13224,13 @@ var $rpc; return receipt; } $rpc.waitForReceipt = waitForReceipt; - function deserialize(model, schema) { + function deserialize(model, schema, schemas) { if (model == null) { return model; } + if (typeof schema === 'string' && schemas != null && schema in schemas) { + schema = schemas[schema]; + } let type = schema; if (typeof schema === 'string') { switch (type) { @@ -13237,6 +13240,8 @@ var $rpc; return BigInt(model); case 'boolean': return Boolean(model); + case 'string': + return model; } } if (Array.isArray(schema)) { @@ -13244,21 +13249,33 @@ var $rpc; if (Array.isArray(model) === false) { throw new Error(`Result must be an array: ${JSON.stringify(model)}`); } - return model.map(x => deserialize(x, schema[0])); + return model.map(x => deserialize(x, schema[0], schemas)); } if (typeof schema === 'object') { let modelType = typeof model; if ('oneOf' in schema) { - let oneOf = schema.oneOf.find(x => typeof x === modelType); + let oneOf = schema.oneOf.find(x => { + if (Array.isArray(x) && Array.isArray(model)) { + let baseType = x[0]; + if (baseType === modelType) { + return true; + } + if (modelType === 'object' && /^[A-Z]/.test(baseType)) { + return true; + } + return false; + } + return typeof x === modelType; + }); if (oneOf) { - return deserialize(model, oneOf); + return deserialize(model, oneOf, schemas); } return model; } if (modelType === 'object') { let out = {}; for (let key in model) { - out[key] = deserialize(model[key], schema[key]); + out[key] = deserialize(model[key], schema[key], schemas); } return out; } @@ -14086,7 +14103,7 @@ class RpcFunction { if (typeof returnsSchema === 'function') { return returnsSchema(result); } - return _rpc_1.$rpc.deserialize(result, returnsSchema); + return _rpc_1.$rpc.deserialize(result, returnsSchema, this.methodInfo.schemas); } return result; }; @@ -14167,7 +14184,10 @@ class RpcBase { } extend(rpcInfos) { rpcInfos.forEach(rpcInfo => { - let fn = new RpcFunction_1.RpcFunction(this, rpcInfo); + let fn = new RpcFunction_1.RpcFunction(this, { + ...rpcInfo, + schemas: this.returnSchemas?.schemas + }); this.fns[rpcInfo.name] = fn.caller(); }); } @@ -14215,7 +14235,7 @@ class RpcBase { if (schema == null || result == null) { return result; } - return _rpc_1.$rpc.deserialize(result, schema); + return _rpc_1.$rpc.deserialize(result, schema, this.returnSchemas?.schemas); } } exports.RpcBase = RpcBase; @@ -14485,6 +14505,25 @@ class Rpc extends RpcBase_1.RpcBase { } }, "schemas": { + "AddEthereumChainParameter": { + "chainId": "string", + "blockExplorerUrls": [ + "string" + ], + "chainName": "string", + "iconUrls": [ + "string" + ], + "nativeCurrency": "NativeCurrency", + "rpcUrls": [ + "string" + ] + }, + "NativeCurrency": { + "decimals": "bigint", + "name": "string", + "symbol": "string" + }, "Permission": { "id": "string", "@context": [ @@ -14498,6 +14537,47 @@ class Rpc extends RpcBase_1.RpcBase { } ] }, + "TypedData": { + "types": {}, + "domain": {}, + "primaryType": "string", + "message": {} + }, + "GenericTransaction": { + "type": "number", + "nonce": "bigint", + "to": "string", + "from": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "gasPrice": "bigint", + "maxPriorityFeePerGas": "bigint", + "maxFeePerGas": "bigint", + "accessList": [ + "AccessListEntry" + ], + "chainId": "bigint" + }, + "AccessListEntry": { + "address": "string", + "storageKeys": [ + "string" + ] + }, + "BlockNumberOrTagOrHash": { + "oneOf": [ + "bigint", + "string", + "string" + ] + }, + "BlockNumberOrTag": { + "oneOf": [ + "bigint", + "string" + ] + }, "Block": { "hash": "string", "parentHash": "string", @@ -14536,6 +14616,101 @@ class Rpc extends RpcBase_1.RpcBase { "string" ] }, + "TransactionInfo": { + "allOf": [ + { + "blockHash": "string", + "blockNumber": "number", + "from": "string", + "hash": "string", + "transactionIndex": "number" + }, + "TransactionSigned" + ] + }, + "TransactionSigned": { + "oneOf": [ + "Transaction1559Signed", + "Transaction2930Signed", + "TransactionLegacySigned" + ] + }, + "Transaction1559Signed": { + "allOf": [ + "Transaction1559Unsigned", + { + "yParity": "number", + "v": "number", + "r": "string", + "s": "string" + } + ] + }, + "Transaction1559Unsigned": { + "type": "number", + "nonce": "number", + "to": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "maxPriorityFeePerGas": "bigint", + "maxFeePerGas": "bigint", + "gasPrice": "bigint", + "accessList": [ + "AccessListEntry" + ], + "chainId": "number" + }, + "Transaction2930Signed": { + "allOf": [ + "Transaction2930Unsigned", + { + "yParity": "number", + "v": "number", + "r": "string", + "s": "string" + } + ] + }, + "Transaction2930Unsigned": { + "type": "number", + "nonce": "number", + "to": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "gasPrice": "bigint", + "accessList": [ + "AccessListEntry" + ], + "chainId": "number" + }, + "TransactionLegacySigned": { + "allOf": [ + "TransactionLegacyUnsigned", + { + "v": "number", + "r": "string", + "s": "string" + } + ] + }, + "TransactionLegacyUnsigned": { + "type": "number", + "nonce": "number", + "to": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "gasPrice": "bigint", + "chainId": "number" + }, + "Withdrawal": { + "index": "bigint", + "validatorIndex": "bigint", + "address": "string", + "amount": "bigint" + }, "FilterResults": { "oneOf": [ [ @@ -14546,6 +14721,42 @@ class Rpc extends RpcBase_1.RpcBase { ] ] }, + "Log": { + "removed": "boolean", + "logIndex": "number", + "transactionIndex": "number", + "transactionHash": "string", + "blockHash": "string", + "blockNumber": "number", + "address": "string", + "data": "string", + "topics": [ + "string" + ] + }, + "Filter": { + "fromBlock": "number", + "toBlock": "number", + "address": { + "oneOf": [ + "string", + [ + "string" + ] + ] + }, + "topics": [ + "FilterTopic" + ] + }, + "FilterTopic": { + "oneOf": [ + "string", + [ + "string" + ] + ] + }, "AccountProof": { "address": "string", "accountProof": [ @@ -14559,16 +14770,11 @@ class Rpc extends RpcBase_1.RpcBase { "StorageProof" ] }, - "TransactionInfo": { - "allOf": [ - { - "blockHash": "string", - "blockNumber": "number", - "from": "string", - "hash": "string", - "transactionIndex": "number" - }, - "TransactionSigned" + "StorageProof": { + "key": "string", + "value": "bigint", + "proof": [ + "string" ] }, "ReceiptInfo": { diff --git a/lib/cli.js b/lib/cli.js index 39600e7..2f2d0dd 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -13234,10 +13234,13 @@ var $rpc; return receipt; } $rpc.waitForReceipt = waitForReceipt; - function deserialize(model, schema) { + function deserialize(model, schema, schemas) { if (model == null) { return model; } + if (typeof schema === 'string' && schemas != null && schema in schemas) { + schema = schemas[schema]; + } let type = schema; if (typeof schema === 'string') { switch (type) { @@ -13247,6 +13250,8 @@ var $rpc; return BigInt(model); case 'boolean': return Boolean(model); + case 'string': + return model; } } if (Array.isArray(schema)) { @@ -13254,21 +13259,33 @@ var $rpc; if (Array.isArray(model) === false) { throw new Error(`Result must be an array: ${JSON.stringify(model)}`); } - return model.map(x => deserialize(x, schema[0])); + return model.map(x => deserialize(x, schema[0], schemas)); } if (typeof schema === 'object') { let modelType = typeof model; if ('oneOf' in schema) { - let oneOf = schema.oneOf.find(x => typeof x === modelType); + let oneOf = schema.oneOf.find(x => { + if (Array.isArray(x) && Array.isArray(model)) { + let baseType = x[0]; + if (baseType === modelType) { + return true; + } + if (modelType === 'object' && /^[A-Z]/.test(baseType)) { + return true; + } + return false; + } + return typeof x === modelType; + }); if (oneOf) { - return deserialize(model, oneOf); + return deserialize(model, oneOf, schemas); } return model; } if (modelType === 'object') { let out = {}; for (let key in model) { - out[key] = deserialize(model[key], schema[key]); + out[key] = deserialize(model[key], schema[key], schemas); } return out; } @@ -14096,7 +14113,7 @@ class RpcFunction { if (typeof returnsSchema === 'function') { return returnsSchema(result); } - return _rpc_1.$rpc.deserialize(result, returnsSchema); + return _rpc_1.$rpc.deserialize(result, returnsSchema, this.methodInfo.schemas); } return result; }; @@ -14177,7 +14194,10 @@ class RpcBase { } extend(rpcInfos) { rpcInfos.forEach(rpcInfo => { - let fn = new RpcFunction_1.RpcFunction(this, rpcInfo); + let fn = new RpcFunction_1.RpcFunction(this, { + ...rpcInfo, + schemas: this.returnSchemas?.schemas + }); this.fns[rpcInfo.name] = fn.caller(); }); } @@ -14225,7 +14245,7 @@ class RpcBase { if (schema == null || result == null) { return result; } - return _rpc_1.$rpc.deserialize(result, schema); + return _rpc_1.$rpc.deserialize(result, schema, this.returnSchemas?.schemas); } } exports.RpcBase = RpcBase; @@ -14495,6 +14515,25 @@ class Rpc extends RpcBase_1.RpcBase { } }, "schemas": { + "AddEthereumChainParameter": { + "chainId": "string", + "blockExplorerUrls": [ + "string" + ], + "chainName": "string", + "iconUrls": [ + "string" + ], + "nativeCurrency": "NativeCurrency", + "rpcUrls": [ + "string" + ] + }, + "NativeCurrency": { + "decimals": "bigint", + "name": "string", + "symbol": "string" + }, "Permission": { "id": "string", "@context": [ @@ -14508,6 +14547,47 @@ class Rpc extends RpcBase_1.RpcBase { } ] }, + "TypedData": { + "types": {}, + "domain": {}, + "primaryType": "string", + "message": {} + }, + "GenericTransaction": { + "type": "number", + "nonce": "bigint", + "to": "string", + "from": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "gasPrice": "bigint", + "maxPriorityFeePerGas": "bigint", + "maxFeePerGas": "bigint", + "accessList": [ + "AccessListEntry" + ], + "chainId": "bigint" + }, + "AccessListEntry": { + "address": "string", + "storageKeys": [ + "string" + ] + }, + "BlockNumberOrTagOrHash": { + "oneOf": [ + "bigint", + "string", + "string" + ] + }, + "BlockNumberOrTag": { + "oneOf": [ + "bigint", + "string" + ] + }, "Block": { "hash": "string", "parentHash": "string", @@ -14546,6 +14626,101 @@ class Rpc extends RpcBase_1.RpcBase { "string" ] }, + "TransactionInfo": { + "allOf": [ + { + "blockHash": "string", + "blockNumber": "number", + "from": "string", + "hash": "string", + "transactionIndex": "number" + }, + "TransactionSigned" + ] + }, + "TransactionSigned": { + "oneOf": [ + "Transaction1559Signed", + "Transaction2930Signed", + "TransactionLegacySigned" + ] + }, + "Transaction1559Signed": { + "allOf": [ + "Transaction1559Unsigned", + { + "yParity": "number", + "v": "number", + "r": "string", + "s": "string" + } + ] + }, + "Transaction1559Unsigned": { + "type": "number", + "nonce": "number", + "to": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "maxPriorityFeePerGas": "bigint", + "maxFeePerGas": "bigint", + "gasPrice": "bigint", + "accessList": [ + "AccessListEntry" + ], + "chainId": "number" + }, + "Transaction2930Signed": { + "allOf": [ + "Transaction2930Unsigned", + { + "yParity": "number", + "v": "number", + "r": "string", + "s": "string" + } + ] + }, + "Transaction2930Unsigned": { + "type": "number", + "nonce": "number", + "to": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "gasPrice": "bigint", + "accessList": [ + "AccessListEntry" + ], + "chainId": "number" + }, + "TransactionLegacySigned": { + "allOf": [ + "TransactionLegacyUnsigned", + { + "v": "number", + "r": "string", + "s": "string" + } + ] + }, + "TransactionLegacyUnsigned": { + "type": "number", + "nonce": "number", + "to": "string", + "gas": "bigint", + "value": "bigint", + "input": "string", + "gasPrice": "bigint", + "chainId": "number" + }, + "Withdrawal": { + "index": "bigint", + "validatorIndex": "bigint", + "address": "string", + "amount": "bigint" + }, "FilterResults": { "oneOf": [ [ @@ -14556,6 +14731,42 @@ class Rpc extends RpcBase_1.RpcBase { ] ] }, + "Log": { + "removed": "boolean", + "logIndex": "number", + "transactionIndex": "number", + "transactionHash": "string", + "blockHash": "string", + "blockNumber": "number", + "address": "string", + "data": "string", + "topics": [ + "string" + ] + }, + "Filter": { + "fromBlock": "number", + "toBlock": "number", + "address": { + "oneOf": [ + "string", + [ + "string" + ] + ] + }, + "topics": [ + "FilterTopic" + ] + }, + "FilterTopic": { + "oneOf": [ + "string", + [ + "string" + ] + ] + }, "AccountProof": { "address": "string", "accountProof": [ @@ -14569,16 +14780,11 @@ class Rpc extends RpcBase_1.RpcBase { "StorageProof" ] }, - "TransactionInfo": { - "allOf": [ - { - "blockHash": "string", - "blockNumber": "number", - "from": "string", - "hash": "string", - "transactionIndex": "number" - }, - "TransactionSigned" + "StorageProof": { + "key": "string", + "value": "bigint", + "proof": [ + "string" ] }, "ReceiptInfo": { diff --git a/package.json b/package.json index 42f436d..632d37d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "0xweb", "description": "Contract package manager and other web3 tools", - "version": "0.10.31", + "version": "0.10.32", "main": "./lib/0xweb.js", "types": "./lib/0xweb.d.ts", "bin": {