Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for network fee. Fix the wrong writing of NEP-10. #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions NeoContract/CGAS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public static object Main(string method, object[] args)
{
var tx = ExecutionEngine.ScriptContainer as Transaction;
var inputs = tx.GetInputs();
if (inputs == null || inputs.Length == 0) return false;
var outputs = tx.GetOutputs();
//Check if the input has been marked
var currentHash = ExecutionEngine.ExecutingScriptHash;
foreach (var input in inputs)
{
if (input.PrevIndex == 0)//If UTXO n is 0, it is possible to be a marker UTXO
Expand All @@ -42,29 +44,29 @@ public static object Main(string method, object[] args)
//If the input that is marked for refund
if (refundMan.Length > 0)
{
//Only one input and one output is allowed in refund
if (inputs.Length != 1 || outputs.Length != 1)
return false;
//Only one input from CGAS address is allowed in refund
var references = tx.GetReferences();
for (int i = 1; i < references.Length; i++)
{
if (references[i].ScriptHash.AsBigInteger() == currentHash.AsBigInteger())
return false;
}
return outputs[0].ScriptHash.AsBigInteger() == refundMan.AsBigInteger();
}
}
}
var currentHash = ExecutionEngine.ExecutingScriptHash;
//If all the inputs are not marked for refund
BigInteger inputAmount = 0;
foreach (var refe in tx.GetReferences())
{
if (refe.AssetId.AsBigInteger() != AssetId.AsBigInteger())
return false;//Not allowed to operate assets other than GAS

if (refe.ScriptHash.AsBigInteger() == currentHash.AsBigInteger())
if (refe.AssetId.AsBigInteger() == AssetId.AsBigInteger() && refe.ScriptHash.AsBigInteger() == currentHash.AsBigInteger())
inputAmount += refe.Value;
}
//Check that there is no money left this contract
//Check that there is no GAS left this contract
BigInteger outputAmount = 0;
foreach (var output in outputs)
{
if (output.ScriptHash.AsBigInteger() == currentHash.AsBigInteger())
if (output.AssetId.AsBigInteger() == AssetId.AsBigInteger() && output.ScriptHash.AsBigInteger() == currentHash.AsBigInteger())
outputAmount += output.Value;
}
return outputAmount == inputAmount;
Expand Down Expand Up @@ -264,7 +266,11 @@ private static void SetTxInfo(byte[] from, byte[] to, BigInteger value)
public static string Symbol() => "CGAS";

[DisplayName("supportedStandards")]
public static string SupportedStandards() => "{\"NEP-5\", \"NEP-7\", \"NEP-10\"}";
public static string[] SupportedStandards()
{
string[] result = { "NEP-5", "NEP-7", "NEP-10" };
return result;
}

[DisplayName("totalSupply")]
public static BigInteger TotalSupply()
Expand Down Expand Up @@ -304,7 +310,7 @@ private static bool Transfer(byte[] from, byte[] to, BigInteger amount, byte[] c
//Increase the payee balance
var toAmount = asset.Get(to).AsBigInteger(); //0.1
asset.Put(to, toAmount + amount); //1

SetTxInfo(from, to, amount);
Transferred(from, to, amount);
return true;
Expand Down
5 changes: 3 additions & 2 deletions Tools/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Neo;
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,9 +14,9 @@ static class Program
static void Main(string[] args)
{
//address 2 script hash
Console.WriteLine(Neo.Wallets.Wallet.ToScriptHash("Ae8AD6Rc3cvQapqttJcUTj9ULfLi2tLHmc"));
Console.WriteLine("Ae8AD6Rc3cvQapqttJcUTj9ULfLi2tLHmc".ToScriptHash());
//script hash 2 address
Console.WriteLine(Neo.Wallets.Wallet.ToAddress(new UInt160("0x505663a29d83663a838eee091249abd167e928f5".Remove(0, 2).HexToBytes().Reverse().ToArray())));
Console.WriteLine(new UInt160("0x505663a29d83663a838eee091249abd167e928f5".Remove(0, 2).HexToBytes().Reverse().ToArray()).ToAddress());

//hex string 2 string
Console.WriteLine("7472616e73666572".HexToString());
Expand Down
24 changes: 18 additions & 6 deletions UnitTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="SQLitePCLRaw.core" publicKeyToken="1488e028ca7ab535" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.11.121" newVersion="1.1.11.121" />
<bindingRedirect oldVersion="0.0.0.0-1.1.13.388" newVersion="1.1.13.388" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
Expand All @@ -31,7 +31,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.EntityFrameworkCore" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.4.0" newVersion="2.1.4.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.2.0" newVersion="2.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
Expand All @@ -51,15 +51,15 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.EntityFrameworkCore.Sqlite" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.4.0" newVersion="2.1.4.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.2.0" newVersion="2.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.EntityFrameworkCore.Relational" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.4.0" newVersion="2.1.4.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.2.0" newVersion="2.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNetCore.WebSockets" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.1.0" newVersion="2.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral" />
Expand All @@ -75,7 +75,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Remotion.Linq" publicKeyToken="fee00910d6e5f53b" culture="neutral" />
Expand Down Expand Up @@ -129,6 +129,18 @@
<assemblyIdentity name="System.Net.WebSockets.WebSocketProtocol" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNetCore.Http" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.2.0" newVersion="2.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.1.0" newVersion="2.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Sqlite" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.2.0" newVersion="2.2.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading