diff --git a/docs/js-api.md b/docs/js-api.md index f1c5341fa..23b440fb9 100644 --- a/docs/js-api.md +++ b/docs/js-api.md @@ -102,19 +102,19 @@ var addressToCreate = "6075EADD0C7A33EE6153F3FA1B21E4D80045FCE2" // The amount we send is arbitrary var amount = 20 -burrow.transact.SendTxSync( - { - Inputs: [{ - Address: Buffer.from(account, 'hex'), - Amount: amount - }], - Outputs: [{ - Address: Buffer.from(addressToCreate, 'hex'), - Amount: amount - }] - }) - .then(txe => console.log(txe)) - .catch(err => console.error(err)) +client.transact.SendTxSync( + { + Inputs: [{ + Address: Buffer.from(account, 'hex'), + Amount: amount + }], + Outputs: [{ + Address: Buffer.from(addressToCreate, 'hex'), + Amount: amount + }] + }) + .then(txe => console.log(txe)) + .catch(err => console.error(err)) ``` The return `txe` (short for `TxExecution`) logged to the console in the `then` block contains the history and fingerprint of the `SendTx` execution. You can see an example of this in [basic app](example/basic-app/app.js). @@ -125,26 +125,30 @@ Here is an example of usage in setting and getting a name: ```javascript var setPayload = { - Input: { - Address: Buffer.from(account,'hex'), - Amount: 50000 - }, - Name: "DOUG", - Data: "Marmot", - Fee: 5000 + Input: { + Address: Buffer.from(account, 'hex'), + Amount: 50000 + }, + Name: "DOUG", + Data: "Marmot", + Fee: 5000 } var getPayload = {Name: "DOUG"} // Using a callback -burrow.transact.NameTxSync(setPayload, function(error, data){ - if (error) throw error; // or something more sensible - // data object contains detailed information of the transaction execution. - - // Get a name this time using a promise - burrow.query.GetName(getPayload) - .then((data) => {console.log(data);}) // should print "Marmot" - .catch((error)=> {throw error;}) +client.transact.NameTxSync(setPayload, function (error, data) { + if (error) throw error; // or something more sensible + // data object contains detailed information of the transaction execution. + + // Get a name this time using a promise + client.query.GetName(getPayload) + .then((data) => { + console.log(data); + }) // should print "Marmot" + .catch((error) => { + throw error; + }) }) ``` @@ -239,14 +243,18 @@ Sets an entry in the namereg. It returns a promise if callback not provided. ```javascript // Using a callback -burrow.namereg.set("DOUG", "Marmot", 5000, function(error, data){ - if (error) throw error; // or something more sensible - // data object contains detailed information of the transaction execution. - - // Get a name this time using a promise - burrow.namereg.get("DOUG") - .then((data) => {console.log(data);}) // Should print "Marmot" - .catch((error)=> {throw error;}) +client.namereg.set("DOUG", "Marmot", 5000, function (error, data) { + if (error) throw error; // or something more sensible + // data object contains detailed information of the transaction execution. + + // Get a name this time using a promise + client.namereg.get("DOUG") + .then((data) => { + console.log(data); + }) // Should print "Marmot" + .catch((error) => { + throw error; + }) }) ``` diff --git a/js/package.json b/js/package.json index b0b579537..b56f470b4 100644 --- a/js/package.json +++ b/js/package.json @@ -20,8 +20,9 @@ "generate:interface": "ts-node src/solts/interface.gd.ts.gr.ts && eslint --fix --quiet src/solts/interface.gd.ts" }, "dependencies": { - "@grpc/grpc-js": "^1.3.0", "@ethersproject/abi": "^5.2.0", + "@grpc/grpc-js": "^1.3.0", + "camel-case": "^4.1.2", "google-protobuf": "^3.15.8", "sha3": "^2.1.4", "solc_v5": "npm:solc@^0.5.17", diff --git a/js/src/solts/api.ts b/js/src/solts/api.ts index 5f9be1e6f..9b39bf738 100644 --- a/js/src/solts/api.ts +++ b/js/src/solts/api.ts @@ -1,5 +1,5 @@ import ts, { factory } from 'typescript'; -import { ABI } from "../contracts/abi"; +import { ABI } from '../contracts/abi'; import { callerTypes, createCallerFunction } from './lib/caller'; import { declareContractType, generateContractObject } from './lib/contract'; import { generateDecodeObject } from './lib/decoder'; @@ -16,7 +16,13 @@ import { getContractMethods } from './lib/solidity'; import { declareConstant, ExportToken, importBurrow, importReadable } from './lib/syntax'; import Func = ABI.Func; -export { decodeOutput, encodeInput, importLocalResolver, inputDescriptionFromFiles, tokenizeLinks } from '../contracts/compile'; +export { + decodeOutput, + encodeInput, + importLocalResolver, + inputDescriptionFromFiles, + tokenizeLinks, +} from '../contracts/compile'; export type Compiled = { name: string; @@ -34,7 +40,6 @@ const abiName = factory.createIdentifier('abi'); export function newFile(contracts: Compiled[], burrowImportPath: string): ts.Node[] { const provider = new Provider(); - const contractNames = contracts.map((c) => factory.createIdentifier(c.name)); return [ ts.addSyntheticLeadingComment( importReadable(), @@ -55,7 +60,14 @@ export function newFile(contracts: Compiled[], burrowImportPath: string): ts.Nod ? [ declareConstant(bytecodeName, factory.createStringLiteral(contract.bytecode, true), true), declareConstant(deployedBytecodeName, factory.createStringLiteral(contract.deployedBytecode, true), true), - generateDeployFunction(deploy, contract.links, provider, abiName, contractNames), + generateDeployFunction( + deploy, + contract.links, + provider, + abiName, + // Exclude names of interface contracts since they have no deployed code + contracts.filter((c) => c.bytecode).map((c) => factory.createIdentifier(c.name)), + ), generateDeployContractFunction(deploy, contract.links, provider), ] : []; diff --git a/js/src/solts/build.ts b/js/src/solts/build.ts index a409c4770..94558e39c 100644 --- a/js/src/solts/build.ts +++ b/js/src/solts/build.ts @@ -1,29 +1,29 @@ -import { promises as fs } from "fs"; -import * as path from "path"; -import * as solcv5 from "solc_v5"; -import * as solcv8 from "solc_v8"; +import { promises as fs } from 'fs'; +import * as path from 'path'; +import * as solcv5 from 'solc_v5'; +import * as solcv8 from 'solc_v8'; import { decodeOutput, encodeInput, importLocalResolver, inputDescriptionFromFiles, - Solidity -} from "../contracts/compile"; -import { Compiled, newFile, printNodes, tokenizeLinks } from "./api"; + Solidity, +} from '../contracts/compile'; +import { Compiled, newFile, printNodes, tokenizeLinks } from './api'; const solcCompilers = { v5: solcv5, - v8: solcv8 + v8: solcv8, } as const; export const defaultBuildOptions = { - solcVersion: "v5" as keyof typeof solcCompilers, - burrowImportPath: (sourceFile: string) => "@hyperledger/burrow" as string, - binPath: "bin" as string, - abiExt: ".abi" as string, + solcVersion: 'v5' as keyof typeof solcCompilers, + burrowImportPath: (sourceFile: string) => '@hyperledger/burrow' as string, + binPath: 'bin' as string | false, + abiExt: '.abi' as string, // Used to resolve layout in bin folder - defaults to srcPath if is passed or process.cwd() otherwise basePath: undefined as undefined | string, - failOnWarnings: false as boolean + failOnWarnings: false as boolean, } as const; export type BuildOptions = typeof defaultBuildOptions; @@ -38,60 +38,62 @@ export type BuildOptions = typeof defaultBuildOptions; export async function build(srcPathOrFiles: string | string[], opts?: Partial): Promise { const { failOnWarnings, solcVersion, binPath, basePath, burrowImportPath, abiExt } = { ...defaultBuildOptions, - ...opts + ...opts, }; - const resolvedBasePath = basePath ?? (typeof srcPathOrFiles === "string" ? srcPathOrFiles : process.cwd()); + const resolvedBasePath = basePath ?? (typeof srcPathOrFiles === 'string' ? srcPathOrFiles : process.cwd()); process.chdir(resolvedBasePath); - const basePathPrefix = new RegExp("^" + path.resolve(resolvedBasePath)); - await fs.mkdir(binPath, { recursive: true }); + const basePathPrefix = new RegExp('^' + path.resolve(resolvedBasePath)); const solidityFiles = await getSourceFilesList(srcPathOrFiles); const inputDescription = inputDescriptionFromFiles( // solidityFiles.map((f) => path.resolve(resolvedBasePath, f.replace(basePathPrefix, ''))), - solidityFiles + solidityFiles, ); const input = encodeInput(inputDescription); const solc = solcCompilers[solcVersion]; const solcOutput = solc.compile(input, { import: importLocalResolver(resolvedBasePath) }); const output = decodeOutput(solcOutput); - const errors = output.errors?.filter((e) => failOnWarnings || (e.severity === "error")) || []; + const errors = output.errors?.filter((e) => failOnWarnings || e.severity === 'error') || []; if (errors.length > 0) { - throw new Error( - "Solidity compiler errors:\n" + formatErrors(errors) - ); + throw new Error('Solidity compiler errors:\n' + formatErrors(errors)); } - const warnings = output.errors?.filter((e) => e.severity === "warning") || []; + const warnings = output.errors?.filter((e) => e.severity === 'warning') || []; if (warnings.length) { - console.error("Solidity compiler warnings (not treated as fatal):\n" + formatErrors(warnings)) + console.error('Solidity compiler warnings (not treated as fatal):\n' + formatErrors(warnings)); } const plan = Object.keys(output.contracts).map((filename) => ({ source: filename, - target: filename.replace(/\.[^/.]+$/, ".abi.ts"), + target: filename.replace(/\.[^/.]+$/, '.abi.ts'), contracts: Object.entries(output.contracts[filename]).map(([name, contract]) => ({ name, - contract - })) + contract, + })), })); - const binPlan = plan.flatMap((f) => { - return f.contracts.map(({ name, contract }) => ({ - source: f.source, - name, - filename: path.join(binPath, path.dirname(path.resolve(f.source)).replace(basePathPrefix, ""), name + abiExt), - abi: JSON.stringify(contract) - })); - }); - - const dupes = findDupes(binPlan, (b) => b.filename); - - if (dupes.length) { - const dupeDescs = dupes.map(({ key, dupes }) => ({ duplicate: key, sources: dupes.map((d) => d.source) })); - throw Error( - `Duplicate contract names found (these contracts will result ABI filenames that will collide since ABIs ` + - `are flattened in '${binPath}'):\n${dupeDescs.map((d) => JSON.stringify(d)).join("\n")}` - ); + let binPlan: { source: string; filename: string; abi: string }[] = []; + + if (binPath !== false) { + await fs.mkdir(binPath, { recursive: true }); + binPlan = plan.flatMap((f) => { + return f.contracts.map(({ name, contract }) => ({ + source: f.source, + name, + filename: path.join(binPath, path.dirname(path.resolve(f.source)).replace(basePathPrefix, ''), name + abiExt), + abi: JSON.stringify(contract), + })); + }); + + const dupes = findDupes(binPlan, (b) => b.filename); + + if (dupes.length) { + const dupeDescs = dupes.map(({ key, dupes }) => ({ duplicate: key, sources: dupes.map((d) => d.source) })); + throw Error( + `Duplicate contract names found (these contracts will result ABI filenames that will collide since ABIs ` + + `are flattened in '${binPath}'):\n${dupeDescs.map((d) => JSON.stringify(d)).join('\n')}`, + ); + } } // Write the ABIs emitted for each file to the name of that file without extension. We flatten into a single @@ -107,11 +109,11 @@ export async function build(srcPathOrFiles: string | string[], opts?: Partial getCompiled(name, contract)), - burrowImportPath(source) - ) - ) - ) - ) + burrowImportPath(source), + ), + ), + ), + ), ]); } @@ -121,7 +123,7 @@ function getCompiled(name: string, contract: Solidity.Contract): Compiled { abi: contract.abi, bytecode: contract.evm.bytecode.object, deployedBytecode: contract.evm.deployedBytecode.object, - links: tokenizeLinks(contract.evm.bytecode.linkReferences) + links: tokenizeLinks(contract.evm.bytecode.linkReferences), }; } @@ -138,15 +140,15 @@ function findDupes(list: T[], by: (t: T) => string): { key: string; dupes: T[ .filter(([_, group]) => group.length > 1) .map(([key, dupes]) => ({ key, - dupes + dupes, })); } async function getSourceFilesList(srcPathOrFiles: string | string[]): Promise { - if (typeof srcPathOrFiles === "string") { + if (typeof srcPathOrFiles === 'string') { const files: string[] = []; for await (const f of walkDir(srcPathOrFiles)) { - if (path.extname(f) === ".sol") { + if (path.extname(f) === '.sol') { files.push(f); } } @@ -167,5 +169,5 @@ async function* walkDir(dir: string): AsyncGenerator { } function formatErrors(errors: Solidity.Error[]): string { - return errors.map((err) => err.formattedMessage || err.message).join("") + return errors.map((err) => err.formattedMessage || err.message).join(''); } diff --git a/js/src/solts/lib/deployer.ts b/js/src/solts/lib/deployer.ts index 8f2261625..073c6ac45 100644 --- a/js/src/solts/lib/deployer.ts +++ b/js/src/solts/lib/deployer.ts @@ -2,7 +2,7 @@ import ts, { factory, FunctionDeclaration, SyntaxKind } from 'typescript'; import { ABI } from '../../contracts/abi'; import { contractFunctionName, contractTypeName } from './contract'; import { callEncodeDeploy, Provider } from './provider'; -import { getRealType, sha3, tokenizeString } from './solidity'; +import { getRealType, libraryName, sha3 } from './solidity'; import { AsyncToken, BooleanType, @@ -17,6 +17,7 @@ import { linkerName, PromiseType, prop, + QuestionToken, StringType, } from './syntax'; @@ -30,6 +31,8 @@ export const withContractMetaName = factory.createIdentifier('withContractMeta') const linkedBytecodeName = factory.createIdentifier('linkedBytecode'); const dataName = factory.createIdentifier('data'); const clientName = factory.createIdentifier('client'); +const librariesName = factory.createIdentifier('libraries'); +const depsName = factory.createIdentifier('deps'); export function generateDeployFunction( abi: ABI.Func | undefined, @@ -54,10 +57,7 @@ export function generateDeployFunction( 'name', factory.createStringLiteral('$' + sha3(link).toLowerCase().slice(0, 34) + '$'), ), - factory.createPropertyAssignment( - 'address', - factory.createIdentifier(tokenizeString(link)), - ), + factory.createPropertyAssignment('address', factory.createIdentifier(libraryName(link))), ]), ), ); @@ -96,7 +96,7 @@ export function generateDeployFunction( undefined, deployName, undefined, - deployParameters(abi, links, provider), + deployParameters(abi, links, provider, true), output, factory.createBlock(statements, true), ); @@ -124,17 +124,56 @@ export function generateDeployContractFunction( createPromiseOf(factory.createTypeReferenceNode(contractTypeName)), factory.createBlock([ declareConstant(addressName, callDeploy), - factory.createReturnStatement(createCall(contractFunctionName, [clientName, addressName])), + factory.createReturnStatement(createCall(contractFunctionName, [prop(depsName, clientName), addressName])), ]), ); } -function deployParameters(abi: ABI.Func | undefined, links: string[], provider: Provider): ts.ParameterDeclaration[] { +function deployParameters( + abi: ABI.Func | undefined, + links: string[], + provider: Provider, + destructure = false, +): ts.ParameterDeclaration[] { const parameters = abi ? abi.inputs?.map((input) => createParameter(input.name, getRealType(input.type))) ?? [] : []; - return [ - createParameter(clientName, provider.type()), - ...links.map((link) => createParameter(factory.createIdentifier(tokenizeString(link)), StringType)), - ...parameters, - createParameter(withContractMetaName, BooleanType, factory.createFalse()), - ]; + return [depsParameter(links, provider, destructure), ...parameters]; +} + +function depsParameter(links: string[], provider: Provider, destructure: boolean): ts.ParameterDeclaration { + const libsType = links.length + ? [ + factory.createPropertySignature( + undefined, + librariesName, + undefined, + factory.createTypeLiteralNode( + links.map((link) => factory.createPropertySignature(undefined, libraryName(link), undefined, StringType)), + ), + ), + ] + : []; + const typeNode = factory.createTypeLiteralNode([ + factory.createPropertySignature(undefined, clientName, undefined, provider.type()), + factory.createPropertySignature(undefined, withContractMetaName, QuestionToken, BooleanType), + ...libsType, + ]); + const libsPattern = links.length + ? [ + factory.createBindingElement( + undefined, + librariesName, + factory.createObjectBindingPattern( + links.map((link) => factory.createBindingElement(undefined, undefined, libraryName(link))), + ), + ), + ] + : []; + const deps = destructure + ? factory.createObjectBindingPattern([ + factory.createBindingElement(undefined, undefined, clientName), + factory.createBindingElement(undefined, undefined, withContractMetaName), + ...libsPattern, + ]) + : depsName; + return createParameter(deps, typeNode); } diff --git a/js/src/solts/lib/solidity.test.ts b/js/src/solts/lib/solidity.test.ts index d966b2634..6fced8cba 100644 --- a/js/src/solts/lib/solidity.test.ts +++ b/js/src/solts/lib/solidity.test.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import { ABI } from '../../contracts/abi'; -import { getSize, nameFromABI, sha3, tokenizeString } from './solidity'; +import { getSize, libraryName, nameFromABI, sha3 } from './solidity'; describe('abi helpers', function () { it('should compute a valid method id', async function () { @@ -30,7 +30,7 @@ describe('abi helpers', function () { assert.equal(getSize('uint[3]'), 3); }); - it('should tokenize string', () => { - assert.equal(tokenizeString('sol/Storage.sol:Storage'), 'sol_Storage_sol_Storage'); + it('should extract library name', () => { + assert.equal(libraryName('sol/Storage.sol:Storage'), 'Storage'); }); }); diff --git a/js/src/solts/lib/solidity.ts b/js/src/solts/lib/solidity.ts index bf21e3e6c..a4880c2c4 100644 --- a/js/src/solts/lib/solidity.ts +++ b/js/src/solts/lib/solidity.ts @@ -1,3 +1,4 @@ +import { camelCase } from 'camel-case'; import { Keccak } from 'sha3'; import ts, { factory, TypeNode } from 'typescript'; import { ABI } from '../../contracts/abi'; @@ -113,8 +114,8 @@ export function getContractMethods(abi: ABI.FunctionOrEvent[]): Method[] { }); } -export function tokenizeString(input: string): string { - return input.replace(/\W+/g, '_'); +export function libraryName(link: string): string { + return link.split(':').slice(-1)[0]; } function getFunctionSelector(abi: ABI.Func): string { diff --git a/js/src/solts/lib/syntax.ts b/js/src/solts/lib/syntax.ts index c4d376329..81306f7f4 100644 --- a/js/src/solts/lib/syntax.ts +++ b/js/src/solts/lib/syntax.ts @@ -124,7 +124,7 @@ function asExp(exp: ts.Expression | string): ts.Expression { } export function createParameter( - name: string | ts.Identifier, + name: string | ts.BindingName, typeNode?: ts.TypeNode, initializer?: ts.Expression, isOptional?: boolean, @@ -134,7 +134,7 @@ export function createParameter( undefined, undefined, isVariadic ? EllipsisToken : undefined, - typeof name === 'string' ? factory.createIdentifier(name) : name, + name, isOptional ? QuestionToken : undefined, typeNode, initializer, diff --git a/js/src/solts/sol/Addition.abi.ts b/js/src/solts/sol/Addition.abi.ts index 9d0cc0ce2..6b6ed0e6e 100644 --- a/js/src/solts/sol/Addition.abi.ts +++ b/js/src/solts/sol/Addition.abi.ts @@ -1,5 +1,5 @@ //Code generated by solts. DO NOT EDIT. -import { Address, CancelStreamSignal, ContractCodec, Event, Keccak } from '../../index'; +import { Address, CancelStreamSignal, ContractCodec, Event, Keccak, linker } from '../../index'; interface Provider { deploy( data: string | Uint8Array, @@ -33,24 +33,47 @@ export async function defaultCall( export namespace Addition { export const contractName = 'Addition'; export const abi = - '[{"constant":true,"inputs":[{"internalType":"int256","name":"a","type":"int256"},{"internalType":"int256","name":"b","type":"int256"}],"name":"add","outputs":[{"internalType":"int256","name":"sum","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"}]'; + '[{"constant":true,"inputs":[{"internalType":"int256","name":"a","type":"int256"},{"internalType":"int256","name":"b","type":"int256"}],"name":"add","outputs":[{"internalType":"int256","name":"sum","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"int256","name":"a","type":"int256"},{"internalType":"int256","name":"b","type":"int256"}],"name":"sub","outputs":[{"internalType":"int256","name":"","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"}]'; export const bytecode = - '608060405234801561001057600080fd5b5060b88061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a5f3c23b14602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506076565b6040518082815260200191505060405180910390f35b600081830190509291505056fea265627a7a72315820bf9f1b3176bb0e5383e0dbeabc3258cbe895f39124127f38452c4ce85df9672964736f6c63430005110032'; + '608060405234801561001057600080fd5b506101b2806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063a5f3c23b1461003b578063adefc37b14610087575b600080fd5b6100716004803603604081101561005157600080fd5b8101908080359060200190929190803590602001909291905050506100d3565b6040518082815260200191505060405180910390f35b6100bd6004803603604081101561009d57600080fd5b8101908080359060200190929190803590602001909291905050506100e0565b6040518082815260200191505060405180910390f35b6000818301905092915050565b60006101758373__$c58c94ed6aafc60c33b5e1db056449bb85$__6325b832d9856040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b15801561013557600080fd5b505af4158015610149573d6000803e3d6000fd5b505050506040513d602081101561015f57600080fd5b81019080805190602001909291905050506100d3565b90509291505056fea265627a7a723158200e39adfefd6f39f3fc67f179a9482aaffb5acf36277d704070d5a0e5f22916c064736f6c63430005110032'; export const deployedBytecode = - '6080604052348015600f57600080fd5b506004361060285760003560e01c8063a5f3c23b14602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506076565b6040518082815260200191505060405180910390f35b600081830190509291505056fea265627a7a72315820bf9f1b3176bb0e5383e0dbeabc3258cbe895f39124127f38452c4ce85df9672964736f6c63430005110032'; - export function deploy(client: Provider, withContractMeta = false): Promise { + '608060405234801561001057600080fd5b50600436106100365760003560e01c8063a5f3c23b1461003b578063adefc37b14610087575b600080fd5b6100716004803603604081101561005157600080fd5b8101908080359060200190929190803590602001909291905050506100d3565b6040518082815260200191505060405180910390f35b6100bd6004803603604081101561009d57600080fd5b8101908080359060200190929190803590602001909291905050506100e0565b6040518082815260200191505060405180910390f35b6000818301905092915050565b60006101758373__$c58c94ed6aafc60c33b5e1db056449bb85$__6325b832d9856040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b15801561013557600080fd5b505af4158015610149573d6000803e3d6000fd5b505050506040513d602081101561015f57600080fd5b81019080805190602001909291905050506100d3565b90509291505056fea265627a7a723158200e39adfefd6f39f3fc67f179a9482aaffb5acf36277d704070d5a0e5f22916c064736f6c63430005110032'; + export function deploy({ + client, + withContractMeta, + libraries: { NegationLib }, + }: { + client: Provider; + withContractMeta?: boolean; + libraries: { + NegationLib: string; + }; + }): Promise { const codec = client.contractCodec(abi); - const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); + const links = [{ name: '$c58c94ed6aafc60c33b5e1db056449bb85$', address: NegationLib }]; + const linkedBytecode = linker(bytecode, links); + const data = Buffer.concat([Buffer.from(linkedBytecode, 'hex'), codec.encodeDeploy()]); return client.deploy( data, withContractMeta - ? [{ abi: Addition.abi, codeHash: new Keccak(256).update(Addition.deployedBytecode, 'hex').digest('binary') }] + ? [ + { + abi: Addition.abi, + codeHash: new Keccak(256).update(linker(Addition.deployedBytecode, links), 'hex').digest('binary'), + }, + ] : undefined, ); } - export async function deployContract(client: Provider, withContractMeta = false): Promise { - const address = await deploy(client, withContractMeta); - return contract(client, address); + export async function deployContract(deps: { + client: Provider; + withContractMeta?: boolean; + libraries: { + NegationLib: string; + }; + }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => @@ -72,6 +95,12 @@ export namespace Addition { return decode(client, data).add(); }); }, + sub(a: number, b: number, call = defaultCall): Promise<[number]> { + const data = encode(client).sub(a, b); + return call<[number]>(client, address, data, true, (data: Uint8Array | undefined) => { + return decode(client, data).sub(); + }); + }, } as const, } as const); export const encode = (client: Provider) => { @@ -80,6 +109,9 @@ export namespace Addition { add: (a: number, b: number) => { return codec.encodeFunctionData('A5F3C23B', a, b); }, + sub: (a: number, b: number) => { + return codec.encodeFunctionData('ADEFC37B', a, b); + }, }; }; export const decode = (client: Provider, data: Uint8Array | undefined, topics: Uint8Array[] = []) => { @@ -91,6 +123,9 @@ export namespace Addition { const [sum] = codec.decodeFunctionResult('A5F3C23B', data); return { sum: sum }; }, + sub: (): [number] => { + return codec.decodeFunctionResult('ADEFC37B', data); + }, }; }; } diff --git a/js/src/solts/sol/Addition.sol b/js/src/solts/sol/Addition.sol index 1e50c0f17..0eec71b70 100644 --- a/js/src/solts/sol/Addition.sol +++ b/js/src/solts/sol/Addition.sol @@ -1,7 +1,13 @@ pragma solidity >=0.0.0; +import "NegationLib.sol"; + contract Addition { function add(int a, int b) public pure returns (int sum) { sum = a + b; } + + function sub(int a, int b) public pure returns (int) { + return add(a, NegationLib.negate(b)); + } } diff --git a/js/src/solts/sol/Contains.abi.ts b/js/src/solts/sol/Contains.abi.ts index 5689c7c5e..7bc5dc81f 100644 --- a/js/src/solts/sol/Contains.abi.ts +++ b/js/src/solts/sol/Contains.abi.ts @@ -38,7 +38,13 @@ export namespace Contains { '608060405234801561001057600080fd5b50610304806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80633da80d661461003b578063b32b8e2c1461012b575b600080fd5b6101116004803603604081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460208302840111640100000000831117156100a257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610205565b604051808215151515815260200191505060405180910390f35b6101eb6004803603604081101561014157600080fd5b810190808035906020019064010000000081111561015e57600080fd5b82018360208201111561017057600080fd5b8035906020019184602083028401116401000000008311171561019257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610280565b604051808215151515815260200191505060405180910390f35b600080600090505b8351811015610274578273ffffffffffffffffffffffffffffffffffffffff1684828151811061023957fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16141561026757600191505061027a565b808060010191505061020d565b50600090505b92915050565b600080600090505b83518110156102c3578284828151811061029e57fe5b602002602001015114156102b65760019150506102c9565b8080600101915050610288565b50600090505b9291505056fea265627a7a7231582032d6f06ddf667cc291458c6ed27a81fe8ef6fa213f3cf25c0fef50500bc05f2264736f6c63430005110032'; export const deployedBytecode = '608060405234801561001057600080fd5b50600436106100365760003560e01c80633da80d661461003b578063b32b8e2c1461012b575b600080fd5b6101116004803603604081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460208302840111640100000000831117156100a257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610205565b604051808215151515815260200191505060405180910390f35b6101eb6004803603604081101561014157600080fd5b810190808035906020019064010000000081111561015e57600080fd5b82018360208201111561017057600080fd5b8035906020019184602083028401116401000000008311171561019257600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610280565b604051808215151515815260200191505060405180910390f35b600080600090505b8351811015610274578273ffffffffffffffffffffffffffffffffffffffff1684828151811061023957fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16141561026757600191505061027a565b808060010191505061020d565b50600090505b92915050565b600080600090505b83518110156102c3578284828151811061029e57fe5b602002602001015114156102b65760019150506102c9565b8080600101915050610288565b50600090505b9291505056fea265627a7a7231582032d6f06ddf667cc291458c6ed27a81fe8ef6fa213f3cf25c0fef50500bc05f2264736f6c63430005110032'; - export function deploy(client: Provider, withContractMeta = false): Promise { + export function deploy({ + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); return client.deploy( @@ -48,9 +54,9 @@ export namespace Contains { : undefined, ); } - export async function deployContract(client: Provider, withContractMeta = false): Promise { - const address = await deploy(client, withContractMeta); - return contract(client, address); + export async function deployContract(deps: { client: Provider; withContractMeta?: boolean }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => diff --git a/js/src/solts/sol/Creator.abi.ts b/js/src/solts/sol/Creator.abi.ts index 50c38b7b3..f21d8b961 100644 --- a/js/src/solts/sol/Creator.abi.ts +++ b/js/src/solts/sol/Creator.abi.ts @@ -38,7 +38,13 @@ export namespace Creator { '608060405234801561001057600080fd5b50610504806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b6a46b3b14610030575b600080fd5b6100a76004803603602081101561004657600080fd5b810190808035906020019064010000000081111561006357600080fd5b82018360208201111561007557600080fd5b8035906020019184600183028401116401000000008311171561009757600080fd5b90919293919293905050506100e9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600082826040516100f990610153565b80806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509350505050604051809103906000f08015801561014a573d6000803e3d6000fd5b50905092915050565b61036f806101618339019056fe60806040526040518060200160405280600081525060009080519060200190610029929190610131565b5034801561003657600080fd5b5060405161036f38038061036f8339818101604052602081101561005957600080fd5b810190808051604051939291908464010000000082111561007957600080fd5b8382019150602082018581111561008f57600080fd5b82518660018202830111640100000000821117156100ac57600080fd5b8083526020830192505050908051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b50604052505050806000908051906020019061012a929190610131565b50506101d6565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061017257805160ff19168380011785556101a0565b828001600101855582156101a0579182015b8281111561019f578251825591602001919060010190610184565b5b5090506101ad91906101b1565b5090565b6101d391905b808211156101cf5760008160009055506001016101b7565b5090565b90565b61018a806101e56000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80636d4ce63c14610030575b600080fd5b6100386100b3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561007857808201518184015260208101905061005d565b50505050905090810190601f1680156100a55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561014b5780601f106101205761010080835404028352916020019161014b565b820191906000526020600020905b81548152906001019060200180831161012e57829003601f168201915b505050505090509056fea265627a7a723158206774e6bd107164a63f42ab8950431a6d5e09eed4da0c066049dc9db7278bbeb364736f6c63430005110032a265627a7a72315820cf64c1da8de972eb1f9f2b5e6799c7af3385d3ee9b08b51fb8d7b060fa7eb4e864736f6c63430005110032'; export const deployedBytecode = '608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b6a46b3b14610030575b600080fd5b6100a76004803603602081101561004657600080fd5b810190808035906020019064010000000081111561006357600080fd5b82018360208201111561007557600080fd5b8035906020019184600183028401116401000000008311171561009757600080fd5b90919293919293905050506100e9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600082826040516100f990610153565b80806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509350505050604051809103906000f08015801561014a573d6000803e3d6000fd5b50905092915050565b61036f806101618339019056fe60806040526040518060200160405280600081525060009080519060200190610029929190610131565b5034801561003657600080fd5b5060405161036f38038061036f8339818101604052602081101561005957600080fd5b810190808051604051939291908464010000000082111561007957600080fd5b8382019150602082018581111561008f57600080fd5b82518660018202830111640100000000821117156100ac57600080fd5b8083526020830192505050908051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b50604052505050806000908051906020019061012a929190610131565b50506101d6565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061017257805160ff19168380011785556101a0565b828001600101855582156101a0579182015b8281111561019f578251825591602001919060010190610184565b5b5090506101ad91906101b1565b5090565b6101d391905b808211156101cf5760008160009055506001016101b7565b5090565b90565b61018a806101e56000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80636d4ce63c14610030575b600080fd5b6100386100b3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561007857808201518184015260208101905061005d565b50505050905090810190601f1680156100a55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561014b5780601f106101205761010080835404028352916020019161014b565b820191906000526020600020905b81548152906001019060200180831161012e57829003601f168201915b505050505090509056fea265627a7a723158206774e6bd107164a63f42ab8950431a6d5e09eed4da0c066049dc9db7278bbeb364736f6c63430005110032a265627a7a72315820cf64c1da8de972eb1f9f2b5e6799c7af3385d3ee9b08b51fb8d7b060fa7eb4e864736f6c63430005110032'; - export function deploy(client: Provider, withContractMeta = false): Promise { + export function deploy({ + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); return client.deploy( @@ -51,9 +57,9 @@ export namespace Creator { : undefined, ); } - export async function deployContract(client: Provider, withContractMeta = false): Promise { - const address = await deploy(client, withContractMeta); - return contract(client, address); + export async function deployContract(deps: { client: Provider; withContractMeta?: boolean }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => @@ -104,7 +110,16 @@ export namespace Proxy { '60806040526040518060200160405280600081525060009080519060200190610029929190610131565b5034801561003657600080fd5b5060405161036f38038061036f8339818101604052602081101561005957600080fd5b810190808051604051939291908464010000000082111561007957600080fd5b8382019150602082018581111561008f57600080fd5b82518660018202830111640100000000821117156100ac57600080fd5b8083526020830192505050908051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b50604052505050806000908051906020019061012a929190610131565b50506101d6565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061017257805160ff19168380011785556101a0565b828001600101855582156101a0579182015b8281111561019f578251825591602001919060010190610184565b5b5090506101ad91906101b1565b5090565b6101d391905b808211156101cf5760008160009055506001016101b7565b5090565b90565b61018a806101e56000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80636d4ce63c14610030575b600080fd5b6100386100b3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561007857808201518184015260208101905061005d565b50505050905090810190601f1680156100a55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561014b5780601f106101205761010080835404028352916020019161014b565b820191906000526020600020905b81548152906001019060200180831161012e57829003601f168201915b505050505090509056fea265627a7a723158206774e6bd107164a63f42ab8950431a6d5e09eed4da0c066049dc9db7278bbeb364736f6c63430005110032'; export const deployedBytecode = '608060405234801561001057600080fd5b506004361061002b5760003560e01c80636d4ce63c14610030575b600080fd5b6100386100b3565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561007857808201518184015260208101905061005d565b50505050905090810190601f1680156100a55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561014b5780601f106101205761010080835404028352916020019161014b565b820191906000526020600020905b81548152906001019060200180831161012e57829003601f168201915b505050505090509056fea265627a7a723158206774e6bd107164a63f42ab8950431a6d5e09eed4da0c066049dc9db7278bbeb364736f6c63430005110032'; - export function deploy(client: Provider, _name: string, withContractMeta = false): Promise { + export function deploy( + { + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }, + _name: string, + ): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy(_name)]); return client.deploy( @@ -117,9 +132,15 @@ export namespace Proxy { : undefined, ); } - export async function deployContract(client: Provider, _name: string, withContractMeta = false): Promise { - const address = await deploy(client, _name, withContractMeta); - return contract(client, address); + export async function deployContract( + deps: { + client: Provider; + withContractMeta?: boolean; + }, + _name: string, + ): Promise { + const address = await deploy(deps, _name); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => diff --git a/js/src/solts/sol/Eventer.abi.ts b/js/src/solts/sol/Eventer.abi.ts index 3acb9a7d9..fcfe712ad 100644 --- a/js/src/solts/sol/Eventer.abi.ts +++ b/js/src/solts/sol/Eventer.abi.ts @@ -38,7 +38,13 @@ export namespace Eventer { '6080604052348015600f57600080fd5b506102b58061001f6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80638f970df014610030575b600080fd5b61003861003a565b005b607b7f6a35688e78094e86ac7dd4593423fa89415105dc68a0766b27106861ef4102146040518080602001806020018381038352600d8152602001807f53616e74612045756c61726961000000000000000000000000000000000000008152506020018381038252600a8152602001807f53616e74204a75616d65000000000000000000000000000000000000000000008152506020019250505060405180910390a27f696e74657276616c3200000000000000000000000000000000000000000000007f6576656e743100000000000000000000000000000000000000000000000000007f5f20df97ee573ab8b43581cf3ff905f3507ad2329b7efe6f92e802b4fad031c17359c99d4ebf520619ee7f806f11d90a9cac02ce06336004604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001806020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200180602001848103845260068152602001807f64696e696e670000000000000000000000000000000000000000000000000000815250602001848103835260098152602001807f627265616b666173740000000000000000000000000000000000000000000000815250602001848103825260178152602001807f6261636f6e2c6265616e732c656767732c746f6d61746f000000000000000000815250602001965050505050505060405180910390a356fea265627a7a72315820a6cd65593c9a8f5ed08f75519d9dd5664bcdf3a4bb67c8f507e1a69ed348f04f64736f6c63430005110032'; export const deployedBytecode = '608060405234801561001057600080fd5b506004361061002b5760003560e01c80638f970df014610030575b600080fd5b61003861003a565b005b607b7f6a35688e78094e86ac7dd4593423fa89415105dc68a0766b27106861ef4102146040518080602001806020018381038352600d8152602001807f53616e74612045756c61726961000000000000000000000000000000000000008152506020018381038252600a8152602001807f53616e74204a75616d65000000000000000000000000000000000000000000008152506020019250505060405180910390a27f696e74657276616c3200000000000000000000000000000000000000000000007f6576656e743100000000000000000000000000000000000000000000000000007f5f20df97ee573ab8b43581cf3ff905f3507ad2329b7efe6f92e802b4fad031c17359c99d4ebf520619ee7f806f11d90a9cac02ce06336004604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001806020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200180602001848103845260068152602001807f64696e696e670000000000000000000000000000000000000000000000000000815250602001848103835260098152602001807f627265616b666173740000000000000000000000000000000000000000000000815250602001848103825260178152602001807f6261636f6e2c6265616e732c656767732c746f6d61746f000000000000000000815250602001965050505050505060405180910390a356fea265627a7a72315820a6cd65593c9a8f5ed08f75519d9dd5664bcdf3a4bb67c8f507e1a69ed348f04f64736f6c63430005110032'; - export function deploy(client: Provider, withContractMeta = false): Promise { + export function deploy({ + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); return client.deploy( @@ -48,9 +54,9 @@ export namespace Eventer { : undefined, ); } - export async function deployContract(client: Provider, withContractMeta = false): Promise { - const address = await deploy(client, withContractMeta); - return contract(client, address); + export async function deployContract(deps: { client: Provider; withContractMeta?: boolean }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); } type EventRegistry = typeof events; export type EventName = keyof EventRegistry; diff --git a/js/src/solts/sol/MultipleReturns.abi.ts b/js/src/solts/sol/MultipleReturns.abi.ts index ff8bb270b..b1cd9a2d8 100644 --- a/js/src/solts/sol/MultipleReturns.abi.ts +++ b/js/src/solts/sol/MultipleReturns.abi.ts @@ -38,7 +38,13 @@ export namespace Multiple { '6080604052348015600f57600080fd5b5060ab8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80636d4ce63c14602d575b600080fd5b60336057565b60405180848152602001838152602001828152602001935050505060405180910390f35b600080600060016002600382925081915080905092509250925090919256fea265627a7a72315820db13aa50f1e1ad94cdc8fb2b158b105d0d0812d53d9851ed8a9bfa5447e3c17864736f6c63430005110032'; export const deployedBytecode = '6080604052348015600f57600080fd5b506004361060285760003560e01c80636d4ce63c14602d575b600080fd5b60336057565b60405180848152602001838152602001828152602001935050505060405180910390f35b600080600060016002600382925081915080905092509250925090919256fea265627a7a72315820db13aa50f1e1ad94cdc8fb2b158b105d0d0812d53d9851ed8a9bfa5447e3c17864736f6c63430005110032'; - export function deploy(client: Provider, withContractMeta = false): Promise { + export function deploy({ + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); return client.deploy( @@ -48,9 +54,9 @@ export namespace Multiple { : undefined, ); } - export async function deployContract(client: Provider, withContractMeta = false): Promise { - const address = await deploy(client, withContractMeta); - return contract(client, address); + export async function deployContract(deps: { client: Provider; withContractMeta?: boolean }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => diff --git a/js/src/solts/sol/NegationLib.abi.ts b/js/src/solts/sol/NegationLib.abi.ts new file mode 100644 index 000000000..91c16afbc --- /dev/null +++ b/js/src/solts/sol/NegationLib.abi.ts @@ -0,0 +1,106 @@ +//Code generated by solts. DO NOT EDIT. +import { Address, CancelStreamSignal, ContractCodec, Event, Keccak } from '../../index'; +interface Provider { + deploy( + data: string | Uint8Array, + contractMeta?: { + abi: string; + codeHash: Uint8Array; + }[], + ): Promise
; + call(data: string | Uint8Array, address: string): Promise; + callSim(data: string | Uint8Array, address: string): Promise; + listen( + signatures: string[], + address: string, + callback: (err?: Error, event?: Event) => CancelStreamSignal | void, + start?: 'first' | 'latest' | 'stream' | number, + end?: 'first' | 'latest' | 'stream' | number, + ): unknown; + contractCodec(contractABI: string): ContractCodec; +} +export type Caller = typeof defaultCall; +export async function defaultCall( + client: Provider, + addr: string, + data: Uint8Array, + isSim: boolean, + callback: (returnData: Uint8Array | undefined) => Output, +): Promise { + const returnData = await (isSim ? client.callSim(data, addr) : client.call(data, addr)); + return callback(returnData); +} +export namespace NegationLib { + export const contractName = 'NegationLib'; + export const abi = + '[{"constant":true,"inputs":[{"internalType":"int256","name":"a","type":"int256"}],"name":"negate","outputs":[{"internalType":"int256","name":"inverse","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"}]'; + export const bytecode = + '60b9610025600b82828239805160001a60731461001857fe5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c806325b832d9146038575b600080fd5b606160048036036020811015604c57600080fd5b81019080803590602001909291905050506077565b6040518082815260200191505060405180910390f35b600081600003905091905056fea265627a7a7231582025f0a2f322c335616644c87b35a42bad6fad892fda8312ab90121566f216478c64736f6c63430005110032'; + export const deployedBytecode = + '730000000000000000000000000000000000000000301460806040526004361060335760003560e01c806325b832d9146038575b600080fd5b606160048036036020811015604c57600080fd5b81019080803590602001909291905050506077565b6040518082815260200191505060405180910390f35b600081600003905091905056fea265627a7a7231582025f0a2f322c335616644c87b35a42bad6fad892fda8312ab90121566f216478c64736f6c63430005110032'; + export function deploy({ + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }): Promise { + const codec = client.contractCodec(abi); + const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); + return client.deploy( + data, + withContractMeta + ? [ + { + abi: NegationLib.abi, + codeHash: new Keccak(256).update(NegationLib.deployedBytecode, 'hex').digest('binary'), + }, + ] + : undefined, + ); + } + export async function deployContract(deps: { client: Provider; withContractMeta?: boolean }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); + } + export type Contract = ReturnType; + export const contract = (client: Provider, address: string) => + ({ + name: 'NegationLib', + address, + functions: { + negate( + a: number, + call = defaultCall, + ): Promise<{ + inverse: number; + }> { + const data = encode(client).negate(a); + return call<{ + inverse: number; + }>(client, address, data, true, (data: Uint8Array | undefined) => { + return decode(client, data).negate(); + }); + }, + } as const, + } as const); + export const encode = (client: Provider) => { + const codec = client.contractCodec(abi); + return { + negate: (a: number) => { + return codec.encodeFunctionData('25B832D9', a); + }, + }; + }; + export const decode = (client: Provider, data: Uint8Array | undefined, topics: Uint8Array[] = []) => { + const codec = client.contractCodec(abi); + return { + negate: (): { + inverse: number; + } => { + const [inverse] = codec.decodeFunctionResult('25B832D9', data); + return { inverse: inverse }; + }, + }; + }; +} diff --git a/js/src/solts/sol/NegationLib.sol b/js/src/solts/sol/NegationLib.sol new file mode 100644 index 000000000..835b2dbff --- /dev/null +++ b/js/src/solts/sol/NegationLib.sol @@ -0,0 +1,7 @@ +pragma solidity >=0.0.0; + +library NegationLib{ + function negate(int a) public pure returns (int inverse) { + inverse = -a; + } +} diff --git a/js/src/solts/sol/Unnamed.abi.ts b/js/src/solts/sol/Unnamed.abi.ts index 9f97f6379..5780ed890 100644 --- a/js/src/solts/sol/Unnamed.abi.ts +++ b/js/src/solts/sol/Unnamed.abi.ts @@ -38,7 +38,13 @@ export namespace Unnamed { '608060405234801561001057600080fd5b5060b88061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806304c402f414602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506076565b6040518082815260200191505060405180910390f35b600082830190509291505056fea265627a7a72315820c692aa5593a39c498f58c4a0221aa0b6ca567436b02c62f90b9214af7b7c390064736f6c63430005110032'; export const deployedBytecode = '6080604052348015600f57600080fd5b506004361060285760003560e01c806304c402f414602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506076565b6040518082815260200191505060405180910390f35b600082830190509291505056fea265627a7a72315820c692aa5593a39c498f58c4a0221aa0b6ca567436b02c62f90b9214af7b7c390064736f6c63430005110032'; - export function deploy(client: Provider, withContractMeta = false): Promise { + export function deploy({ + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy()]); return client.deploy( @@ -48,9 +54,9 @@ export namespace Unnamed { : undefined, ); } - export async function deployContract(client: Provider, withContractMeta = false): Promise { - const address = await deploy(client, withContractMeta); - return contract(client, address); + export async function deployContract(deps: { client: Provider; withContractMeta?: boolean }): Promise { + const address = await deploy(deps); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => diff --git a/js/src/solts/sol/storage/Storage.abi.ts b/js/src/solts/sol/storage/Storage.abi.ts index f6078f8c7..dc0aa7930 100644 --- a/js/src/solts/sol/storage/Storage.abi.ts +++ b/js/src/solts/sol/storage/Storage.abi.ts @@ -38,7 +38,16 @@ export namespace Storage { '608060405234801561001057600080fd5b506040516101203803806101208339818101604052602081101561003357600080fd5b8101908080519060200190929190505050806000819055505060c68061005a6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80636d4ce63c146037578063e5c19b2d146053575b600080fd5b603d607e565b6040518082815260200191505060405180910390f35b607c60048036036020811015606757600080fd5b81019080803590602001909291905050506087565b005b60008054905090565b806000819055505056fea265627a7a72315820df6fea8cbd336a45734df49c645eb1a45497cd5babf1e4c20c340998d6d9cb6264736f6c63430005110032'; export const deployedBytecode = '6080604052348015600f57600080fd5b506004361060325760003560e01c80636d4ce63c146037578063e5c19b2d146053575b600080fd5b603d607e565b6040518082815260200191505060405180910390f35b607c60048036036020811015606757600080fd5b81019080803590602001909291905050506087565b005b60008054905090565b806000819055505056fea265627a7a72315820df6fea8cbd336a45734df49c645eb1a45497cd5babf1e4c20c340998d6d9cb6264736f6c63430005110032'; - export function deploy(client: Provider, x: number, withContractMeta = false): Promise { + export function deploy( + { + client, + withContractMeta, + }: { + client: Provider; + withContractMeta?: boolean; + }, + x: number, + ): Promise { const codec = client.contractCodec(abi); const data = Buffer.concat([Buffer.from(bytecode, 'hex'), codec.encodeDeploy(x)]); return client.deploy( @@ -48,9 +57,15 @@ export namespace Storage { : undefined, ); } - export async function deployContract(client: Provider, x: number, withContractMeta = false): Promise { - const address = await deploy(client, x, withContractMeta); - return contract(client, address); + export async function deployContract( + deps: { + client: Provider; + withContractMeta?: boolean; + }, + x: number, + ): Promise { + const address = await deploy(deps, x); + return contract(deps.client, address); } export type Contract = ReturnType; export const contract = (client: Provider, address: string) => diff --git a/js/src/test/175.test.ts b/js/src/test/175.test.ts index 589f72bc1..c0fd26209 100644 --- a/js/src/test/175.test.ts +++ b/js/src/test/175.test.ts @@ -1,7 +1,7 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; import { ContractInstance, getMetadata } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('#175', function () { it('#175', async () => { @@ -20,8 +20,8 @@ describe('#175', function () { const contract = compile(source, 'Contract'); - const instance1 = (await contract.deploy(burrow, 'contract1')) as any; - const instance2 = await contract.deploy(burrow, 'contract2'); + const instance1 = (await contract.deploy(client, 'contract1')) as any; + const instance2 = await contract.deploy(client, 'contract2'); const address = getMetadata(instance2).address; const ps = await Promise.all([ diff --git a/js/src/test/44.test.ts b/js/src/test/44.test.ts index 34368c68d..10c468fca 100644 --- a/js/src/test/44.test.ts +++ b/js/src/test/44.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#44', function () { it('#44', async () => { @@ -19,7 +19,7 @@ describe('#44', function () { } `; const contract = compile(source, 'SimpleStorage'); - const instance: any = await contract.deploy(burrow); + const instance: any = await contract.deploy(client); await instance.set('88977A37D05A4FE86D09E88C88A49C2FCF7D6D8F'); const data = await instance.get(); diff --git a/js/src/test/45.test.ts b/js/src/test/45.test.ts index f9c7bbf1b..488ee52bf 100644 --- a/js/src/test/45.test.ts +++ b/js/src/test/45.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#45', function () { it('Set/get memory string', async () => { @@ -24,7 +24,7 @@ describe('#45', function () { `; const contract = compile(source, 'Test'); return contract - .deploy(burrow) + .deploy(client) .then((instance: any) => instance.setName('Batman').then(() => instance.getName())) .then((value) => { assert.deepStrictEqual(value, ['Batman']); @@ -48,7 +48,7 @@ describe('#45', function () { `; const contract = compile(source, 'Test'); - return contract.deploy(burrow).then((instance: any) => + return contract.deploy(client).then((instance: any) => Promise.all([instance.getAddress(), instance.getNumber()]).then(([address, number]) => { assert.strictEqual(address[0].length, 40); assert.strictEqual(number[0], 100); diff --git a/js/src/test/46.test.ts b/js/src/test/46.test.ts index 7f002a8c9..3ae974426 100644 --- a/js/src/test/46.test.ts +++ b/js/src/test/46.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#46', function () { it('#46', async () => { @@ -26,7 +26,7 @@ describe('#46', function () { const contract = compile(source, 'Test'); return contract - .deploy(burrow) + .deploy(client) .then((instance: any) => instance.setName('Batman').then(() => Promise.all([instance.getNameConstant(), instance.getName()])), ) diff --git a/js/src/test/47.test.ts b/js/src/test/47.test.ts index dfbe416ec..f52ad3ca0 100644 --- a/js/src/test/47.test.ts +++ b/js/src/test/47.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#47', function () { it('#47', async () => { @@ -21,7 +21,7 @@ describe('#47', function () { `; const contract = compile(source, 'Test'); return contract - .deploy(burrow) + .deploy(client) .then((instance: any) => Promise.all([instance.getWithSpaceConstant(), instance.getWithoutSpaceConstant()])) .then(([withSpace, withoutSpace]) => { assert.deepStrictEqual(withSpace, [' Pieter']); diff --git a/js/src/test/48.test.ts b/js/src/test/48.test.ts index 547a06c78..17633bec8 100644 --- a/js/src/test/48.test.ts +++ b/js/src/test/48.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#48', function () { it('#48', async () => { @@ -25,7 +25,7 @@ describe('#48', function () { `; const contract = compile(source, 'Test'); return contract - .deploy(burrow) + .deploy(client) .then((instance: any) => instance.getCombination()) .then(([number, address]) => { assert.strictEqual(number, 100); diff --git a/js/src/test/50.test.ts b/js/src/test/50.test.ts index 184ca5afe..00d0415dc 100644 --- a/js/src/test/50.test.ts +++ b/js/src/test/50.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#50', function () { it('#50', async () => { @@ -19,7 +19,7 @@ describe('#50', function () { } `; const contract = compile(source, 'SimpleStorage'); - const instance = await contract.deploy(burrow); + const instance = await contract.deploy(client); await instance.set(42); const value = await instance.get.call(); assert.deepStrictEqual([...value], [42]); diff --git a/js/src/test/61.test.ts b/js/src/test/61.test.ts index 066aa4e76..94d5946c3 100644 --- a/js/src/test/61.test.ts +++ b/js/src/test/61.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('#61', function () { it('#61', async () => { @@ -19,7 +19,7 @@ describe('#61', function () { } `; const contract = compile(source, 'SimpleStorage'); - const instance = await contract.deploy(burrow, '88977A37D05A4FE86D09E88C88A49C2FCF7D6D8F'); + const instance = await contract.deploy(client, '88977A37D05A4FE86D09E88C88A49C2FCF7D6D8F'); const value = await instance.get(); assert.deepStrictEqual([...value], ['88977A37D05A4FE86D09E88C88A49C2FCF7D6D8F']); }); diff --git a/js/src/test/abis.test.ts b/js/src/test/abis.test.ts index ba05beda4..f78ef758a 100644 --- a/js/src/test/abis.test.ts +++ b/js/src/test/abis.test.ts @@ -1,7 +1,7 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; import { getAddress } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('Abi', function () { const source = ` @@ -16,12 +16,12 @@ contract random { // TODO: understand why abi storage isn't working it('Call contract via burrow side Abi', async () => { const contract = compile(source, 'random'); - const instance: any = await contract.deploy(burrow); - await burrow.namereg.set('random', getAddress(instance)); - const entry = await burrow.namereg.get('random'); + const instance: any = await contract.deploy(client); + await client.namereg.set('random', getAddress(instance)); + const entry = await client.namereg.get('random'); const address = entry.getData(); console.log(address); - const contractOut: any = await contract.at(address, burrow); + const contractOut: any = await contract.at(address, client); const number = await contractOut.getRandomNumber(); assert.strictEqual(number[0], 55); }); diff --git a/js/src/test/bn.test.ts b/js/src/test/bn.test.ts index 27c4cec77..a79a7f7d1 100644 --- a/js/src/test/bn.test.ts +++ b/js/src/test/bn.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('BN', function () { it('BN', async () => { @@ -17,7 +17,7 @@ describe('BN', function () { } `; const contract = compile(source, 'Test'); - const instance = await contract.deploy(burrow); + const instance = await contract.deploy(client); const [number] = await instance.getNumber(); assert.strictEqual(number.toString(), '10000000000000000000'); diff --git a/js/src/test/contract-event.test.ts b/js/src/test/contract-event.test.ts index 4e2320acd..7f3e41d18 100644 --- a/js/src/test/contract-event.test.ts +++ b/js/src/test/contract-event.test.ts @@ -1,6 +1,6 @@ import { compile } from '../contracts/compile'; import { ContractEvent, getAddress } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('Nested contract event emission', function () { it('#38', async () => { @@ -15,7 +15,7 @@ describe('Nested contract event emission', function () { } `; const contract = compile(source, 'Contract'); - const instance: any = await contract.deploy(burrow); + const instance: any = await contract.deploy(client); const event = instance.Event as ContractEvent; const stream = event.at(getAddress(instance), function (error, result) { if (error) { diff --git a/js/src/test/event-listen.test.ts b/js/src/test/event-listen.test.ts index 754886362..eb0d7efc0 100644 --- a/js/src/test/event-listen.test.ts +++ b/js/src/test/event-listen.test.ts @@ -2,7 +2,7 @@ import { LogDescription } from '@ethersproject/abi'; import * as assert from 'assert'; import { compile } from '../contracts/compile'; import { ContractEvent } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('Event listening', function () { it('listens to an event from a contract', async () => { @@ -34,7 +34,7 @@ describe('Event listening', function () { `; const contract = compile(source, 'Contract'); - const instance = await contract.deploy(burrow); + const instance = await contract.deploy(client); const promise = new Promise((resolve, reject) => { const pay = instance.Pay as ContractEvent; const stream = pay((error, result) => { diff --git a/js/src/test/event.test.ts b/js/src/test/event.test.ts index 7f42eff77..cdbbe57ab 100644 --- a/js/src/test/event.test.ts +++ b/js/src/test/event.test.ts @@ -1,7 +1,7 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; import { ContractEvent } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('event', function () { it('listens to an event from a contract', async () => { @@ -18,7 +18,7 @@ describe('event', function () { } `; const contract = compile(source, 'Contract'); - const instance: any = await contract.deploy(burrow); + const instance: any = await contract.deploy(client); let count = 0; const event = instance.Event as ContractEvent; diff --git a/js/src/test/flipper.test.ts b/js/src/test/flipper.test.ts index 17788aad9..d4f10f99f 100644 --- a/js/src/test/flipper.test.ts +++ b/js/src/test/flipper.test.ts @@ -1,7 +1,7 @@ import * as assert from 'assert'; import fs from 'fs'; import { Contract } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('Wasm flipper:', function () { let TestContract: any; @@ -9,7 +9,7 @@ describe('Wasm flipper:', function () { before(async () => { const abi: any[] = JSON.parse(fs.readFileSync('src/test/flipper.abi', 'utf-8')); const wasm: string = fs.readFileSync('src/test/flipper.wasm').toString('hex'); - TestContract = await new Contract({ abi, bytecode: wasm }).deploy(burrow, true); + TestContract = await new Contract({ abi, bytecode: wasm }).deploy(client, true); }); it('Flip', async () => { diff --git a/js/src/test/functional.test.ts b/js/src/test/functional.test.ts index 45e7ef340..fd5431b35 100644 --- a/js/src/test/functional.test.ts +++ b/js/src/test/functional.test.ts @@ -1,7 +1,7 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; import { getMetadata } from '../contracts/contract'; -import { burrow } from './test'; +import { client } from './test'; describe('Functional Contract Usage', function () { it('#Constructor usage', async () => { @@ -34,8 +34,8 @@ describe('Functional Contract Usage', function () { const contract = compile(source, 'Test'); const [instance1, instance2] = await Promise.all([ - contract.deploy(burrow, '88977A37D05A4FE86D09E88C88A49C2FCF7D6D8F'), - contract.deploy(burrow, 'ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF0123'), + contract.deploy(client, '88977A37D05A4FE86D09E88C88A49C2FCF7D6D8F'), + contract.deploy(client, 'ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEF0123'), ]); const address1 = getMetadata(instance1).address; diff --git a/js/src/test/get-set.test.ts b/js/src/test/get-set.test.ts index 42b730d68..7b99c50fe 100644 --- a/js/src/test/get-set.test.ts +++ b/js/src/test/get-set.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('Setting and Getting Values:', function () { const source = ` @@ -68,7 +68,7 @@ contract GetSet { before(async () => { const contract = compile(source, 'GetSet'); - TestContract = await contract.deploy(burrow); + TestContract = await contract.deploy(client); }); it('Uint', async () => { diff --git a/js/src/test/handler-overwriting.test.ts b/js/src/test/handler-overwriting.test.ts index b0c5c8cba..9e1603827 100644 --- a/js/src/test/handler-overwriting.test.ts +++ b/js/src/test/handler-overwriting.test.ts @@ -3,7 +3,7 @@ import { CallResult } from '../contracts/call'; import { compile } from '../contracts/compile'; import { getMetadata } from '../contracts/contract'; import { withoutArrayElements } from '../convert'; -import { burrow } from './test'; +import { client } from './test'; describe('Testing Per-contract handler overwriting', function () { // {handlers: {call: function (result) { return {super: result.values, man: result.raw} }}}) @@ -31,7 +31,7 @@ describe('Testing Per-contract handler overwriting', function () { } `; - const instance: any = await compile(source, 'Test').deployWith(burrow, { + const instance: any = await compile(source, 'Test').deployWith(client, { handler: function ({ result }: CallResult) { return { values: withoutArrayElements(result), diff --git a/js/src/test/infloop.test.ts b/js/src/test/infloop.test.ts index 8734507db..fb6b274df 100644 --- a/js/src/test/infloop.test.ts +++ b/js/src/test/infloop.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('Really Long Loop', function () { let instance: any; @@ -28,7 +28,7 @@ describe('Really Long Loop', function () { `; const contract = compile(source, 'main'); - instance = await contract.deployWith(burrow, { + instance = await contract.deployWith(client, { middleware: (callTx) => { // Normal gas for deploy (when address === '') if (callTx.getAddress()) { diff --git a/js/src/test/memory-bytes.test.ts b/js/src/test/memory-bytes.test.ts index 13ad30531..f81d1a7c0 100644 --- a/js/src/test/memory-bytes.test.ts +++ b/js/src/test/memory-bytes.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('memory bytes', function () { let instance: any; @@ -28,7 +28,7 @@ describe('memory bytes', function () { `; const contract = compile(source, 'c'); - instance = await contract.deploy(burrow); + instance = await contract.deploy(client); }); it('gets the static byte array decoded properly', async () => { diff --git a/js/src/test/namereg.test.ts b/js/src/test/namereg.test.ts index 4b0cffc2c..74f3fd29d 100644 --- a/js/src/test/namereg.test.ts +++ b/js/src/test/namereg.test.ts @@ -1,12 +1,12 @@ import * as assert from 'assert'; -import { burrow } from './test'; +import { client } from './test'; describe('Namereg', function () { this.timeout(10 * 1000); it('Sets and gets a name correctly', async () => { - await burrow.namereg.set('DOUG', 'ABCDEF0123456789', 5000, 100); - const entry = await burrow.namereg.get('DOUG'); + await client.namereg.set('DOUG', 'ABCDEF0123456789', 5000, 100); + const entry = await client.namereg.get('DOUG'); assert.strictEqual(entry.getData(), 'ABCDEF0123456789'); }); }); diff --git a/js/src/test/return-types.test.ts b/js/src/test/return-types.test.ts index 5c68ea542..d10528035 100644 --- a/js/src/test/return-types.test.ts +++ b/js/src/test/return-types.test.ts @@ -2,7 +2,7 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; import { getAddress } from '../contracts/contract'; import { withoutArrayElements } from '../convert'; -import { burrow } from './test'; +import { client } from './test'; describe('Multiple return types', function () { it('can decode multiple returns', async () => { @@ -28,7 +28,7 @@ describe('Multiple return types', function () { } `; const contract = compile(source, 'Test'); - const instance: any = await contract.deployWith(burrow, { + const instance: any = await contract.deployWith(client, { handler: function ({ result }) { return { values: withoutArrayElements(result), diff --git a/js/src/test/revert.test.ts b/js/src/test/revert.test.ts index 70195a767..f123fdb7a 100644 --- a/js/src/test/revert.test.ts +++ b/js/src/test/revert.test.ts @@ -1,7 +1,7 @@ import * as grpc from '@grpc/grpc-js'; import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('REVERT constant', function () { let instance: any; @@ -21,7 +21,7 @@ describe('REVERT constant', function () { } `; - instance = await compile(source, 'c').deploy(burrow); + instance = await compile(source, 'c').deploy(client); }); it('gets the string when revert not called', async () => { diff --git a/js/src/test/revert2.test.ts b/js/src/test/revert2.test.ts index 9f7558a8c..eeed5a539 100644 --- a/js/src/test/revert2.test.ts +++ b/js/src/test/revert2.test.ts @@ -1,7 +1,7 @@ import * as grpc from '@grpc/grpc-js'; import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('REVERT non-constant', function () { let instance: any; @@ -23,7 +23,7 @@ describe('REVERT non-constant', function () { } `; - instance = await compile(source, 'c').deploy(burrow); + instance = await compile(source, 'c').deploy(client); }); it('gets the string when revert not called', async () => { diff --git a/js/src/test/revert3.test.ts b/js/src/test/revert3.test.ts index 66de75b8f..f8711a03a 100644 --- a/js/src/test/revert3.test.ts +++ b/js/src/test/revert3.test.ts @@ -1,7 +1,7 @@ import * as grpc from '@grpc/grpc-js'; import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('REVERT non-constant', function () { let instance: any; @@ -23,7 +23,7 @@ describe('REVERT non-constant', function () { } `; - instance = await compile(source, 'c').deploy(burrow); + instance = await compile(source, 'c').deploy(client); }); it('It catches a revert with the revert string', async () => { diff --git a/js/src/test/simple-storage.test.ts b/js/src/test/simple-storage.test.ts index aab4922bd..564b41267 100644 --- a/js/src/test/simple-storage.test.ts +++ b/js/src/test/simple-storage.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { compile } from '../contracts/compile'; -import { burrow } from './test'; +import { client } from './test'; describe('Simple storage', function () { it('sets and gets a value from a contract', async () => { @@ -20,7 +20,7 @@ describe('Simple storage', function () { `; const contract = compile(source, 'SimpleStorage'); return contract - .deploy(burrow) + .deploy(client) .then((instance: any) => instance.set(42).then(() => instance.get())) .then((value) => { assert.deepStrictEqual([...value], [42]); diff --git a/js/src/test/solts.test.ts b/js/src/test/solts.test.ts index 7bb215cdb..b6beefa58 100644 --- a/js/src/test/solts.test.ts +++ b/js/src/test/solts.test.ts @@ -2,17 +2,19 @@ import * as assert from 'assert'; import { readEvents } from '../events'; import { Addition } from '../solts/sol/Addition.abi'; import { Eventer } from '../solts/sol/Eventer.abi'; -import { burrow } from './test'; +import { NegationLib } from '../solts/sol/NegationLib.abi'; +import { client } from './test'; describe('solts', () => { it('can deploy and call from codegen', async () => { - const adder = await Addition.deployContract(burrow, true); + const libraries = { NegationLib: await NegationLib.deploy({ client }) }; + const adder = await Addition.deployContract({ client, libraries: libraries, withContractMeta: true }); const { sum } = await adder.functions.add(2342, 23432); assert.strictEqual(sum, 25774); }); it('can receive events', async () => { - const eventer = await Eventer.deployContract(burrow, true); + const eventer = await Eventer.deployContract({ client, withContractMeta: true }); await eventer.functions.announce(); await eventer.functions.announce(); await eventer.functions.announce(); @@ -24,7 +26,7 @@ describe('solts', () => { }); it('can listen to multiple events', async () => { - const eventer = await Eventer.deployContract(burrow, true); + const eventer = await Eventer.deployContract({ client, withContractMeta: true }); await eventer.functions.announce(); await eventer.functions.announce(); const listener = eventer.listenerFor(['MonoRampage', 'Init']); diff --git a/js/src/test/test.ts b/js/src/test/test.ts index fdf01066b..500950bb5 100644 --- a/js/src/test/test.ts +++ b/js/src/test/test.ts @@ -2,4 +2,4 @@ import { Client } from '../index'; const url = process.env.BURROW_URL || 'localhost:20123'; const addr = process.env.SIGNING_ADDRESS || 'C9F239591C593CB8EE192B0009C6A0F2C9F8D768'; -export const burrow = new Client(url, addr); +export const client = new Client(url, addr); diff --git a/js/yarn.lock b/js/yarn.lock index 3b9b83923..18abc97f3 100644 --- a/js/yarn.lock +++ b/js/yarn.lock @@ -516,6 +516,14 @@ callsites@^3.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== +camel-case@^4.1.2: + version "4.1.2" + resolved "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz#9728072a954f805228225a6deea6b38461e1bd5a" + integrity sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw== + dependencies: + pascal-case "^3.1.2" + tslib "^2.0.3" + camelcase@^6.0.0: version "6.2.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" @@ -1345,6 +1353,13 @@ log-symbols@4.0.0: dependencies: chalk "^4.0.0" +lower-case@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz#6fa237c63dbdc4a82ca0fd882e4722dc5e634e28" + integrity sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg== + dependencies: + tslib "^2.0.3" + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" @@ -1484,6 +1499,14 @@ neo-async@^2.6.0: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c" integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw== +no-case@^3.0.4: + version "3.0.4" + resolved "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d" + integrity sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg== + dependencies: + lower-case "^2.0.2" + tslib "^2.0.3" + node-pre-gyp@^0.15.0: version "0.15.0" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.15.0.tgz#c2fc383276b74c7ffa842925241553e8b40f1087" @@ -1612,6 +1635,14 @@ parent-module@^1.0.0: dependencies: callsites "^3.0.0" +pascal-case@^3.1.2: + version "3.1.2" + resolved "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz#b48e0ef2b98e205e7c1dae747d0b1508237660eb" + integrity sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + path-exists@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" @@ -2048,6 +2079,11 @@ tslib@^1.8.1: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== +tslib@^2.0.3: + version "2.3.0" + resolved "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e" + integrity sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg== + tsutils@^3.17.1: version "3.21.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" diff --git a/project/history.go b/project/history.go index 0383127be..5ed4a7e4f 100644 --- a/project/history.go +++ b/project/history.go @@ -46,7 +46,11 @@ func FullVersion() string { // To cut a new release add a release to the front of this slice then run the // release tagging script: ./scripts/tag_release.sh History relic.ImmutableHistory = relic.NewHistory("Hyperledger Burrow", "https://github.com/hyperledger/burrow"). - MustDeclareReleases("0.34.3 - 2021-07-19", + MustDeclareReleases("0.34.4 - 2021-07-23", + `### Changed +- [JS] Make deploy and deployContract take deps argument consisting of deployment options and library object. The library object makes it easier to pass an identical object with the addresses of commonly used libraries under their canonical names. +`, + "0.34.3 - 2021-07-19", `### Fixed - [JS] Fix spelling of 'contractName' in solts, add contract name to contract object.