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. #4

Merged
merged 2 commits into from
Sep 11, 2020
Merged
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
26 changes: 16 additions & 10 deletions NeoContract/CNEO.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,25 +44,25 @@ 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 CNEO 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 NEO

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

[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 @@ -310,4 +316,4 @@ private static bool Transfer(byte[] from, byte[] to, BigInteger amount, byte[] c
return true;
}
}
}
}