From 2215e3e39966e6a68c62d53feabf13baf15741c8 Mon Sep 17 00:00:00 2001 From: Vitor Nazario Coelho Date: Tue, 21 Nov 2023 11:50:21 -0300 Subject: [PATCH] added check overflow for compiler and button for finding network fee optimized --- assets/eco-scripts/contracts.js | 56 +++++++++++++++- assets/eco-scripts/rawRpc.js | 67 ++++++++++--------- .../docker-compiler-csharp/Dockerfile | 2 +- .../docker-compiler-csharp/entrypoint.sh | 8 +-- .../docker-compiler-csharp/file.csproj | 5 +- index.html | 26 +++++-- 6 files changed, 116 insertions(+), 48 deletions(-) diff --git a/assets/eco-scripts/contracts.js b/assets/eco-scripts/contracts.js index efa5c6ee..5fee0ff3 100644 --- a/assets/eco-scripts/contracts.js +++ b/assets/eco-scripts/contracts.js @@ -246,7 +246,7 @@ function drawParametersTable() { var paramInput = document.createElement('input'); paramInput.setAttribute('id', "paramInput" + p); - paramInput.setAttribute("class", "form-control"); + paramInput.setAttribute("class", "form-control"); paramInput.placeholder = method.parameters[p].name + "(" + method.parameters[p].type + ")"; txRow.insertCell(-1).appendChild(paramInput); } //Finishes loop that draws each relayed transaction @@ -389,7 +389,7 @@ function invokeFunctionWithParams(contractHash, method, params, relay = false) { var jsonForInvokingFunction = { "jsonrpc": "2.0", - "id": 5, + "id": 1, "method": "invokefunction", "params": invokeparams }; @@ -397,7 +397,10 @@ function invokeFunctionWithParams(contractHash, method, params, relay = false) { goToTabAndClick("nav-rpc"); var jsonToCallStringified = JSON.stringify(jsonForInvokingFunction); $("#txtRPCJson").val(jsonToCallStringified); - rawRpcCall(true, -1, relay); + + var fillNextTx = true; + var saveID = -1; + rawRpcCall(fillNextTx, saveID, relay); } function invokeFunction() { @@ -443,6 +446,53 @@ function invokeFunction() { invokeFunctionWithParams(CONTRACTS_TO_LIST[getCurrentSelectedContract()].hash, method.name, params); } +function findNetworkFee() { + if (!checkIfWalletIsConnected()) + return; + var sysFee = Math.ceil(getFixed8Integer($("#sys_fee")[0].value)); + var validUntil = Number($("#valid_until")[0].value); + var script = $("#tx_script")[0].value; + + var netFee = Math.ceil(getFixed8Integer($("#net_fee")[0].value)); + + const tx = new Neon.tx.Transaction({ + signers: [{ + account: ECO_WALLET[CONNECTED_WALLET_ID].account.scriptHash, + scopes: Neon.tx.WitnessScope.CalledByEntry, + },], + validUntilBlock: validUntil, + script: script, + systemFee: sysFee, + networkFee: netFee, + }) + + signTx(tx); + console.log(tx) + + var rawTX = Neon.u.hex2base64(tx.serialize(true)); + console.log(rawTX) + var jsonForInvokingFunction = { + "jsonrpc": "2.0", + "id": 10, + "method": "calculatenetworkfee", + "params": [rawTX] + }; + + var jsonToCallStringified = JSON.stringify(jsonForInvokingFunction); + console.log(jsonToCallStringified) + $.post( + BASE_PATH_CLI, // Gets the URL to sent the post to + jsonToCallStringified, // Serializes form data in standard format + function (netFeeResult) { + console.log(netFeeResult); + console.log("calculated fee is:" + netFeeResult..result.networkfee); + $("#net_fee")[0].value = netFeeResult.result.networkfee / getFixed8(); + }, + "json" // The format the response should be in + ).fail(function () { + $("#txtRPCJsonOut").val("failed to invoke network!"); + }); //End of POST for search +} function getNativeContractIndexByName(contractName) { for (nc = 0; nc < NATIVE_CONTRACTS.length; nc++) diff --git a/assets/eco-scripts/rawRpc.js b/assets/eco-scripts/rawRpc.js index 3346ac1a..c6faf3fb 100644 --- a/assets/eco-scripts/rawRpc.js +++ b/assets/eco-scripts/rawRpc.js @@ -94,8 +94,9 @@ function fillRealTxFromInvokeFunction() { }); return; } + $("#sys_fee")[0].value = invokeResult.result.gasconsumed / getFixed8(); - $("#net_fee")[0].value = 10000000 / getFixed8(); + $("#net_fee")[0].value = 20000000 / getFixed8(); $("#tx_script")[0].value = Neon.u.base642hex(invokeResult.result.script); $("#valid_until")[0].value = Neon.tx.Transaction.MAX_TRANSACTION_LIFESPAN + LAST_BEST_HEIGHT_NEOCLI - 1; drawSigners(); @@ -125,8 +126,6 @@ function signAndRelay(blinkRelay = true) { } var signerHash = ECO_WALLET[CONNECTED_WALLET_ID].account.scriptHash; - - invokeWithParametersDAPI(CONNECTED_DAPI_WALLET_OBJ, netFee, dapiParams.params[0], dapiParams.params[1], dapiParams.params[2], signerHash); return; @@ -150,33 +149,7 @@ function signAndRelay(blinkRelay = true) { networkFee: netFee, }) - if (isMultiSig(CONNECTED_WALLET_ID)) { - var publicKeys = Neon.wallet.getPublicKeysFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script)) - var threshold = Neon.wallet.getSigningThresholdFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script)) - var signingAccountsIDs = getMultiSigSignersID(publicKeys, threshold); - if (signingAccountsIDs.length < threshold) { - swal({ - title: "Current Wallet is connected to a multisig!", - text: "Your wallet has " + signingAccountsIDs.length + " accounts to sign. But required is " + threshold, - icon: "error", - button: "Ok!", - timer: 5500, - }); - } - - for (sa = 0; sa < signingAccountsIDs.length; sa++) - tx.sign(ECO_WALLET[signingAccountsIDs[sa]].account, NETWORK_MAGIC) - - const multisigWitness = Neon.tx.Witness.buildMultiSig( - tx.serialize(false), - tx.witnesses, - ECO_WALLET[CONNECTED_WALLET_ID].account - ); - - tx.witnesses = [multisigWitness]; - } else { - tx.sign(ECO_WALLET[CONNECTED_WALLET_ID].account, NETWORK_MAGIC) - } + signTx(tx); var relayedTX = []; relayedTX.push({ @@ -194,9 +167,11 @@ function signAndRelay(blinkRelay = true) { console.log(tx) console.log(tx.serialize(true)) var rawTX = Neon.u.hex2base64(tx.serialize(true)); + + var jsonForInvokingFunction = { "jsonrpc": "2.0", - "id": 5, + "id": 2, "method": "sendrawtransaction", "params": [rawTX] }; @@ -206,4 +181,34 @@ function signAndRelay(blinkRelay = true) { rawRpcCall(false, RELAYED_TXS.length - 1, false, blinkRelay); //var client = new Neon.rpc.RPCClient(BASE_PATH_CLI); //RELAYED_TXS.push(client.sendRawTransaction(tx)); +} + +function signTx(tx){ + if (isMultiSig(CONNECTED_WALLET_ID)) { + var publicKeys = Neon.wallet.getPublicKeysFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script)) + var threshold = Neon.wallet.getSigningThresholdFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script)) + var signingAccountsIDs = getMultiSigSignersID(publicKeys, threshold); + if (signingAccountsIDs.length < threshold) { + swal({ + title: "Current Wallet is connected to a multisig!", + text: "Your wallet has " + signingAccountsIDs.length + " accounts to sign. But required is " + threshold, + icon: "error", + button: "Ok!", + timer: 5500, + }); + } + + for (sa = 0; sa < signingAccountsIDs.length; sa++) + tx.sign(ECO_WALLET[signingAccountsIDs[sa]].account, NETWORK_MAGIC) + + const multisigWitness = Neon.tx.Witness.buildMultiSig( + tx.serialize(false), + tx.witnesses, + ECO_WALLET[CONNECTED_WALLET_ID].account + ); + + tx.witnesses = [multisigWitness]; + } else { + tx.sign(ECO_WALLET[CONNECTED_WALLET_ID].account, NETWORK_MAGIC) + } } \ No newline at end of file diff --git a/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/Dockerfile b/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/Dockerfile index af8b79ae..8e7c51a7 100644 --- a/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/Dockerfile +++ b/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/Dockerfile @@ -21,7 +21,7 @@ RUN (cd /neo-devpack-dotnet/src/Neo.Compiler.CSharp && dotnet build) #COPY file.csproj /neo-devpack-dotnet/templates/Template.NEP17.CSharp/Template.NEP17.CSharp.csproj RUN mkdir /neo-devpack-dotnet/src/Template.CSharpNeoCompiler -COPY file.csproj /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/Template.CSharpNeoCompiler.csproj +COPY file.csproj /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/NeoCompilerContractGenerated.csproj ADD entrypoint.sh /entrypoint.sh diff --git a/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/entrypoint.sh b/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/entrypoint.sh index 25d00093..7c9e1b1a 100755 --- a/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/entrypoint.sh +++ b/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/entrypoint.sh @@ -42,16 +42,16 @@ cat /tmp/output.txt | base64 -w 0 >> /tmp/return.txt # Add new output related to the AVM, ABI and MANIFEST echo -n "\", \"nef\": \"" >> /tmp/return.txt -if [ -f /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/Template.CSharpNeoCompiler.nef ]; then - cat /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/Template.CSharpNeoCompiler.nef | base64 -w 0 >> /tmp/return.txt +if [ -f /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/NeoCompilerContractGenerated.nef ]; then + cat /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/NeoCompilerContractGenerated.nef | base64 -w 0 >> /tmp/return.txt fi #echo -n "\", \"abi\":\"" >> /tmp/return.txt #if [ -f /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/Template.CSharpNeoCompiler.abi.json ]; then # cat /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/Template.CSharpNeoCompiler.abi.json | base64 -w 0 >> /tmp/return.txt #fi echo -n "\", \"manifest\":\"" >> /tmp/return.txt -if [ -f /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/Template.CSharpNeoCompiler.manifest.json ]; then - cat /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/Template.CSharpNeoCompiler.manifest.json | base64 -w 0 >> /tmp/return.txt +if [ -f /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/NeoCompilerContractGenerated.manifest.json ]; then + cat /neo-devpack-dotnet/src/Template.CSharpNeoCompiler/bin/sc/NeoCompilerContractGenerated.manifest.json | base64 -w 0 >> /tmp/return.txt fi echo -n "\"}" >> /tmp/return.txt diff --git a/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/file.csproj b/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/file.csproj index c5426d32..45ffb147 100644 --- a/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/file.csproj +++ b/docker-sock-express-compilers/docker-compilers/compilers/docker-compiler-csharp/file.csproj @@ -2,7 +2,8 @@ --base-name $(AssemblyName) - --base-name $(MSBuildProjectName) + --base-name $(MSBuildProjectName) + --checked net7.0 @@ -13,7 +14,7 @@ - + diff --git a/index.html b/index.html index b7dcd5dd..020b5191 100644 --- a/index.html +++ b/index.html @@ -419,13 +419,15 @@

+ onchange="createNativeManifest()" class="form-select checkedOption" + size="8">
+ onchange="createLocalManifest()" class="form-select checkedOption" + size="8">
@@ -513,12 +515,13 @@

Request from Neo C# nodes (RPC-JSON API)

Method (view Official API or put cursor on top for tooltip) --> -
-
@@ -551,6 +554,15 @@

Request from Neo C# nodes (RPC-JSON API)

+
+
+ +
+
+
@@ -747,8 +759,8 @@

Transfer NEP17 Tokens

-