diff --git a/CHANGELOG.md b/CHANGELOG.md index 7233ee6..2c752f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ All notable changes to this project will be documented in this file. +## [1.6.0] - 2023-02-13 + +### New + +- Added [support of Signature ID](https://github.com/tonlabs/ever-sdk/blob/master/CHANGELOG.md) on the networks with + `CapSignatureWithId` capability enabled. +- Added new option `everdev contract deploy --workchain` to specify in which workchain to deploy a contract. +- `everdev contract decode-tvc` command renamed to `everdev contract decode-stateinit`. +- Add a reference to stable solc and sold versions to the output of the + `everdev sold version` and `everdev sol version` commands. + +### Fixed + +- Double error messages generated by `everdev sol compile` command. +- Error: `unrecognized option '-i` which occurred when using a solidity compiler version below 0.57.0 +- The "constructor" function excluded from the list of callable functions +- Incorrect `GiverV1.abi.json` file has been replaced with the correct one. +- Set the `se` network as the default network if there is no default network. +- Set the `seGiver` giver as the default signer if there is no default signer. + ## [1.5.1] - 2022-12-23 ### New diff --git a/contracts/GiverV1.abi.json b/contracts/GiverV1.abi.json index e50b453..5e16e54 100644 --- a/contracts/GiverV1.abi.json +++ b/contracts/GiverV1.abi.json @@ -1,29 +1,20 @@ { - "ABI version": 2, - "version": "2.2", - "header": [ - "pubkey", - "time", - "expire" - ], - "functions": [ - { - "name": "sendGrams", - "inputs": [ + "ABI version": 1, + "functions": [ { - "name": "dest", - "type": "address" + "name": "constructor", + "inputs": [], + "outputs": [] }, { - "name": "amount", - "type": "uint64" + "name": "sendGrams", + "inputs": [ + { "name": "dest", "type": "address" }, + { "name": "amount", "type": "uint64" } + ], + "outputs": [] } - ], - "outputs": [ - ] - } - ], - "data": [], - "events": [], - "fields": [] + ], + "events": [], + "data": [] } diff --git a/contracts/GiverV3.abi.json b/contracts/GiverV3.abi.json index a75bcf7..7749f9f 100644 --- a/contracts/GiverV3.abi.json +++ b/contracts/GiverV3.abi.json @@ -1,49 +1,49 @@ { - "ABI version": 2, - "version": "2.2", - "header": ["time", "expire"], - "functions": [ - { - "name": "sendTransaction", - "inputs": [ - {"name":"dest","type":"address"}, - {"name":"value","type":"uint128"}, - {"name":"bounce","type":"bool"} - ], - "outputs": [ - ] - }, - { - "name": "getMessages", - "inputs": [ - ], - "outputs": [ - {"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint64"}],"name":"messages","type":"tuple[]"} - ] - }, - { - "name": "upgrade", - "inputs": [ - {"name":"newcode","type":"cell"} - ], - "outputs": [ - ] - }, - { - "name": "constructor", - "inputs": [ - ], - "outputs": [ - ] - } - ], - "data": [ - ], - "events": [ - ], - "fields": [ - {"name":"_pubkey","type":"uint256"}, - {"name":"_constructorFlag","type":"bool"}, - {"name":"m_messages","type":"map(uint256,uint64)"} - ] + "ABI version": 2, + "version": "2.3", + "header": ["time", "expire"], + "functions": [ + { + "name": "sendTransaction", + "inputs": [ + {"name":"dest","type":"address"}, + {"name":"value","type":"uint128"}, + {"name":"bounce","type":"bool"} + ], + "outputs": [ + ] + }, + { + "name": "getMessages", + "inputs": [ + ], + "outputs": [ + {"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint32"}],"name":"messages","type":"tuple[]"} + ] + }, + { + "name": "upgrade", + "inputs": [ + {"name":"newcode","type":"cell"} + ], + "outputs": [ + ] + }, + { + "name": "constructor", + "inputs": [ + ], + "outputs": [ + ] + } + ], + "data": [ + ], + "events": [ + ], + "fields": [ + {"name":"_pubkey","type":"uint256"}, + {"name":"_constructorFlag","type":"bool"}, + {"name":"m_messages","type":"map(uint256,uint32)"} + ] } diff --git a/contracts/GiverV3.keys.json b/contracts/GiverV3.keys.json deleted file mode 100644 index e3d8285..0000000 --- a/contracts/GiverV3.keys.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "public": "2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16", - "secret": "172af540e43a524763dd53b26a066d472a97c4de37d5498170564510608250c3" -} \ No newline at end of file diff --git a/contracts/GiverV3.sol b/contracts/GiverV3.sol index 5f08ed4..c1f69e1 100644 --- a/contracts/GiverV3.sol +++ b/contracts/GiverV3.sol @@ -1,4 +1,4 @@ -pragma ton-solidity >= 0.59.0; +pragma ever-solidity >= 0.61.2; pragma AbiHeader time; pragma AbiHeader expire; @@ -22,7 +22,7 @@ abstract contract Upgradable { contract GiverV3 is Upgradable { uint8 constant MAX_CLEANUP_MSGS = 30; - mapping(uint256 => uint64) m_messages; + mapping(uint256 => uint32) m_messages; modifier acceptOnlyOwner { require(msg.pubkey() == tvm.pubkey(), 101); @@ -49,19 +49,19 @@ contract GiverV3 is Upgradable { /// @notice Function with predefined name called after signature check. Used to /// implement custom replay protection with parallel access. - function afterSignatureCheck(TvmSlice body, TvmCell message) private inline + function afterSignatureCheck(TvmSlice body, TvmCell) private inline returns (TvmSlice) { // owner check require(msg.pubkey() == tvm.pubkey(), 101); + uint256 bodyHash = tvm.hash(body); // load and drop message timestamp (uint64) - (, uint64 expireAt) = body.decode(uint64, uint32); + (, uint32 expireAt) = body.decode(uint64, uint32); require(expireAt > now, 57); - uint256 msgHash = tvm.hash(message); - require(!m_messages.exists(msgHash), 102); + require(!m_messages.exists(bodyHash), 102); tvm.accept(); - m_messages[msgHash] = expireAt; + m_messages[bodyHash] = expireAt; return body; } @@ -69,13 +69,13 @@ contract GiverV3 is Upgradable { /// @notice Allows to delete expired messages from dict. function gc() private inline { uint counter = 0; - for ((uint256 msgHash, uint64 expireAt) : m_messages) { + for ((uint256 bodyHash, uint32 expireAt) : m_messages) { if (counter >= MAX_CLEANUP_MSGS) { break; } counter++; if (expireAt <= now) { - delete m_messages[msgHash]; + delete m_messages[bodyHash]; } } } @@ -85,10 +85,10 @@ contract GiverV3 is Upgradable { */ struct Message { uint256 hash; - uint64 expireAt; + uint32 expireAt; } function getMessages() public view returns (Message[] messages) { - for ((uint256 msgHash, uint64 expireAt) : m_messages) { + for ((uint256 msgHash, uint32 expireAt) : m_messages) { messages.push(Message(msgHash, expireAt)); } } diff --git a/contracts/GiverV3.tvc b/contracts/GiverV3.tvc new file mode 100644 index 0000000..96a3c21 Binary files /dev/null and b/contracts/GiverV3.tvc differ diff --git a/contracts/GiverV2.keys.json b/contracts/seGiver.keys.json similarity index 100% rename from contracts/GiverV2.keys.json rename to contracts/seGiver.keys.json diff --git a/docs/guides/quick-start.md b/docs/guides/quick-start.md index 4802c6a..11efb5b 100644 --- a/docs/guides/quick-start.md +++ b/docs/guides/quick-start.md @@ -87,7 +87,7 @@ $ everdev s l Signer Public Key Used -------------------- ---------------------------------------------------------------- --------------------------- -giver_keys 2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16 se network giver signer +seGiver 2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16 se network giver signer EverNode SE Default Giver Keys owner_keys (Default) 3826202b129ea8c041b8d49a655512648fc94377d1958a7a4fc9f4b3051ecf7b ``` diff --git a/docs/guides/work-with-devnet.md b/docs/guides/work-with-devnet.md index d84b8a9..5020ba9 100644 --- a/docs/guides/work-with-devnet.md +++ b/docs/guides/work-with-devnet.md @@ -5,8 +5,9 @@ - [Working with DevNet: deploy and start using your own giver in Developer Network](#working-with-devnet-deploy-and-start-using-your-own-giver-in-developer-network) - [Contents](#contents) - [Deploying your own Giver](#deploying-your-own-giver) + - [Get your Devnet credentials](#get-your-devnet-credentials) - [Generate Giver keys](#generate-giver-keys) - - [Compile Giver code](#compile-giver-code) + - [Get giver code](#get-giver-code) - [Calculate Giver address](#calculate-giver-address) - [Sponsor Giver with public faucet](#sponsor-giver-with-public-faucet) - [Deploy Giver contract](#deploy-giver-contract) @@ -19,6 +20,17 @@ Working with DevNet is similar to working with SE except you usually don't have In order to deploy the Giver, do the following steps, like for an ordinary contract: +### Get your Devnet credentials + +First, go to https://www.evercloud.dev/ and register in the dashboard. +Follow this instruction: https://docs.evercloud.dev/products/evercloud/get-started. +Save your project ID and secret, if you enabled it. + +Now, run this command. Specifying secret is optional - only if you enabled it: +``` +$ everdev network credentials dev --project "Project Id" --access-key "Project secret" +``` + ### Generate Giver keys ``` @@ -31,29 +43,20 @@ test (Default) de101cde5c94540926fe862e965cf109b1b803989e7048657cf7c4caaa2a2 devnet_giver_keys 5a343ccbd62c15e3df1076bc34957ad2717469d84e4d6b3ef26112db80ac8e1b ``` -### Compile Giver code +### Get giver code -You can find compiled giver v2 contract with code [here](https://github.com/tonlabs/evernode-se/tree/master/contracts/giver_v2). You need to recompile code only if you want to change its code, so you can use compiled `GiverV2.tvc` file and move to the next step. - -**Attention!** -The code in repo is not compatible with the latest Solidity compilers, so if you would like to compile it yourself, you would need to migrate code to the latest Solidity version first. - -After modifying code, compile it: -``` -$ everdev sol compile GiverV2.sol -``` -In a case of success, compiler will generate two files: compiled code (`GiverV2.tvc`) and ABI (`GiverV2.abi.json`). You need these files for the next steps. +You can find the compiled giver v3 contract [here](https://github.com/tonlabs/evernode-se/tree/master/contracts/giver_v3). You will need `GiverV3.tvc` file. ### Calculate Giver address In order to deploy contract, you need to know its address: ``` -$ everdev contract info -n dev -s devnet_giver_keys GiverV2.tvc +$ everdev contract info -n dev -s devnet_giver_keys GiverV3.tvc Configuration - Network: dev (net.ton.dev, net1.ton.dev, net5.ton.dev) + Network: dev Signer: devnet_giver_keys (public 5a343ccbd62c15e3df1076bc34957ad2717469d84e4d6b3ef26112db80ac8e1b) Address: 0:93139197f2f58d674bee4ee71a42d8f1e7b6a3c3e041ded7a54d330bcc44f3b3 (calculated from TVC and signer public) @@ -75,14 +78,14 @@ Wait for operation completion. Check address balance in [Blockchain Explorer](ht ### Deploy Giver contract -For contract deployment you need to have compiled contract files (`GiverV2.tvc` and `GiverV2.abi.json`) and giver keys. To deploy contract execute next command: +For contract deployment you need to have compiled contract files (`GiverV3.tvc` and `GiverV3.abi.json`) and giver keys. To deploy contract execute next command: ``` -$ everdev contract deploy -n dev -s devnet_giver_keys GiverV2.tvc +$ everdev contract deploy -n dev -s devnet_giver_keys GiverV3.tvc Configuration - Network: dev (eri01.net.everos.dev, rbx01.net.everos.dev, gra01.net.everos.dev) + Network: dev Signer: devnet_giver_keys (public 5a343ccbd62c15e3df1076bc34957ad2717469d84e4d6b3ef26112db80ac8e1b) Address: 0:93139197f2f58d674bee4ee71a42d8f1e7b6a3c3e041ded7a54d330bcc44f3b3 (calculated from TVC and signer public) @@ -98,20 +101,20 @@ Done, now you have your own Giver, deployed to the DevNet! Let's configure `ever For convenience, you might need to configure `everdev` in order to use your Giver as default. To do it, execute the next command (change address to your Giver's address, obtained on previous steps): ``` -$ everdev network giver dev 0:93139197f2f58d674bee4ee71a42d8f1e7b6a3c3e041ded7a54d330bcc44f3b3 --signer devnet_giver_keys +$ everdev n g dev 0:93139197f2f58d674bee4ee71a42d8f1e7b6a3c3e041ded7a54d330bcc44f3b3 --signer devnet_giver_keys --type GiverV3 ``` Check: ``` -$ everdev n l -Network Endpoints Giver ------------- ----------------------------------------------- ------------------------------------------------------------------ -se (Default) http://localhost 0:b5e9240fc2d2f1ff8cbb1d1dee7fb7cae155e5f6320e585fcc685698994a19a5 - GiverV2 -dev eri01.net.everos.dev, rbx01.net.everos.dev, gra01.net.everos.dev 0:93139197f2f58d674bee4ee71a42d8f1e7b6a3c3e041ded7a54d330bcc44f3b3 - GiverV2 signed by devnet_giver_keys -main eri01.main.everos.dev, gra01.main.everos.dev, gra02.main.everos.dev ... +everdev n l +Network Endpoints Giver +------------ --------------------- ------------------------------------------------------------------ +se (Default) http://localhost 0:ece57bcc6c530283becbbd8a3b24d3c5987cdddc3c8b7b33be6e4a6312490415 + GiverV3 signed by seGiver +dev devnet.evercloud.dev 0:93139197f2f58d674bee4ee71a42d8f1e7b6a3c3e041ded7a54d330bcc44f3b3 + GiverV3 signed by devnet_giver_keys +main mainnet.evercloud.dev ``` If Giver is set, you will see you Giver's address and keypair name for the `dev` network. @@ -125,7 +128,7 @@ $ everdev contract topup --network dev --address
--value 10000 Configuration - Network: dev (eri01.net.everos.dev, rbx01.net.everos.dev, gra01.net.everos.dev) + Network: dev Signer: test (public de101cde5c94540926fe862e965cf109b1b803989e7048657cf7c4caaa2a257d) Address: diff --git a/package.json b/package.json index cdbc0c6..4e3f894 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "everdev", - "version": "1.5.1", + "version": "1.6.0", "description": "Everscale Dev Environment", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -46,8 +46,8 @@ }, "dependencies": { "@eversdk/appkit": "^0.3.4", - "@eversdk/core": "^1.39.0", - "@eversdk/lib-node": "^1.39.0", + "@eversdk/core": "^1.41.1", + "@eversdk/lib-node": "^1.41.1", "chalk": "^2.4.2", "dockerode": "^3.3.1", "fs-extra": "^9.1.0", diff --git a/src/__tests__/parser.ts b/src/__tests__/parser.ts index b2894f9..28bc767 100644 --- a/src/__tests__/parser.ts +++ b/src/__tests__/parser.ts @@ -6,6 +6,7 @@ import { solidityCreateCommand, } from "../controllers/solidity" +import { NetworkTool, networkGiverCommand } from "../controllers/network" beforeAll(initTests) afterAll(doneTests) @@ -98,3 +99,72 @@ test("everdev create a.sol b.sol, should throw", async () => { expect(err.message).toMatch(/Unexpected argument/) } }) + +test("everdev network add giver with address in negative workchain", async () => { + const parser = new CommandLine() + await parser.parse([ + "network", + "giver", + "networkName", + "-2:1111111111111111111111111111111111111111111111111111111111111111", + "-s", + "seGiver", + "-t", + "GiverV1", + ]) + const { controller, command, args } = parser + expect(controller).toEqual(NetworkTool) + expect(command).toEqual(networkGiverCommand) + expect(args).toEqual({ + name: "networkName", + address: + "-2:1111111111111111111111111111111111111111111111111111111111111111", + signer: "seGiver", + type: "GiverV1", + value: "", + }) +}) + +test("everdev network add giver with address in positive workchain", async () => { + const parser = new CommandLine() + await parser.parse([ + "network", + "giver", + "networkName", + "0:1111111111111111111111111111111111111111111111111111111111111111", + "-s", + "seGiver", + "-t", + "GiverV1", + ]) + const { controller, command, args } = parser + expect(controller).toEqual(NetworkTool) + expect(command).toEqual(networkGiverCommand) + expect(args).toEqual({ + name: "networkName", + address: + "0:1111111111111111111111111111111111111111111111111111111111111111", + signer: "seGiver", + type: "GiverV1", + value: "", + }) +}) + +test("everdev network add giver with malformed address in negative workchain", async () => { + const parser = new CommandLine() + try { + await parser.parse([ + "network", + "giver", + "networkName", + "-1w:123", + "-s", + "seGiver", + "-t", + "GiverV1", + ]) + throw Error("Shouldn't resolve!") + } catch (err) { + expect(err.message).toMatch(/Unknown option/) + } +}) diff --git a/src/cli/index.ts b/src/cli/index.ts index 1196307..f5324ed 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -143,11 +143,17 @@ export class CommandLine { } } } - async parse(programArgs: string[]) { for (let i = 0; i < programArgs.length; i++) { let arg = programArgs[i] - if (arg.startsWith("-") && !this.pending) { + if ( + arg.startsWith("-") && + !this.pending && + // exclude positional parameters - addressess in negative workchains. + // Don't require 64 digits after ':', thus repeating parser behavior + // for addresses in positive working chains + /^-[0-9a-f]+:/.test(arg) === false + ) { await this.parseOptionName(arg) } else { arg = arg.trim() diff --git a/src/controllers/contract/accounts.ts b/src/controllers/contract/accounts.ts index 549bf2a..5faa2ff 100644 --- a/src/controllers/contract/accounts.ts +++ b/src/controllers/contract/accounts.ts @@ -25,9 +25,18 @@ export async function getAccount( signer: string data: string address?: string + workchain?: string }, ): Promise