Skip to content

Commit d293d65

Browse files
author
陈志同
committed
Merging transfer and transferAPP
1 parent b055adb commit d293d65

File tree

3 files changed

+7
-42
lines changed

3 files changed

+7
-42
lines changed

NeoContract/CGAS.cs

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ public static object Main(string method, object[] args)
9494
if (method == "totalSupply") return TotalSupply();
9595

9696
if (method == "transfer") return Transfer((byte[])args[0], (byte[])args[1], (BigInteger)args[2], callscript);
97-
98-
if (method == "transferAPP") return TransferAPP((byte[])args[0], (byte[])args[1], (BigInteger)args[2], callscript);
9997
}
10098
else if (Runtime.Trigger == TriggerType.VerificationR) //Backward compatibility, refusing to accept other assets
10199
{
@@ -163,7 +161,7 @@ public static bool MintTokens()
163161
{
164162
if (input.AssetId.AsBigInteger() == AssetId.AsBigInteger())
165163
sender = sender ?? input.ScriptHash;
166-
//SGAS address as inputs is not allowed
164+
//CGAS address as inputs is not allowed
167165
if (input.ScriptHash.AsBigInteger() == ExecutionEngine.ExecutingScriptHash.AsBigInteger())
168166
return false;
169167
}
@@ -288,42 +286,9 @@ private static bool Transfer(byte[] from, byte[] to, BigInteger amount, byte[] c
288286
throw new InvalidOperationException("The parameter amount MUST be greater than 0.");
289287
if (ExecutionEngine.EntryScriptHash.AsBigInteger() != callscript.AsBigInteger())
290288
return false;
291-
if (!IsPayable(to) || !Runtime.CheckWitness(from)/*0.2*/)
292-
return false;
293-
StorageMap asset = Storage.CurrentContext.CreateMap(nameof(asset));
294-
var fromAmount = asset.Get(from).AsBigInteger(); //0.1
295-
if (fromAmount < amount)
289+
if (!IsPayable(to))
296290
return false;
297-
if (from == to)
298-
return true;
299-
300-
//Reduce payer balances
301-
if (fromAmount == amount)
302-
asset.Delete(from); //0.1
303-
else
304-
asset.Put(from, fromAmount - amount); //1
305-
306-
//Increase the payee balance
307-
var toAmount = asset.Get(to).AsBigInteger(); //0.1
308-
asset.Put(to, toAmount + amount); //1
309-
310-
SetTxInfo(from, to, amount);
311-
Transferred(from, to, amount);
312-
return true;
313-
}
314-
#if DEBUG
315-
[DisplayName("transferAPP")] //Only for ABI file
316-
public static bool TransferAPP(byte[] from, byte[] to, BigInteger amount) => true;
317-
#endif
318-
//Methods of actual execution
319-
private static bool TransferAPP(byte[] from, byte[] to, BigInteger amount, byte[] callscript)
320-
{
321-
//Check parameters
322-
if (from.Length != 20 || to.Length != 20)
323-
throw new InvalidOperationException("The parameters from and to SHOULD be 20-byte addresses.");
324-
if (amount <= 0)
325-
throw new InvalidOperationException("The parameter amount MUST be greater than 0.");
326-
if (!IsPayable(to) || from.AsBigInteger() != callscript.AsBigInteger())
291+
if (!Runtime.CheckWitness(from) && from.AsBigInteger() != callscript.AsBigInteger()) /*0.2*/
327292
return false;
328293
StorageMap asset = Storage.CurrentContext.CreateMap(nameof(asset));
329294
var fromAmount = asset.Get(from).AsBigInteger(); //0.1

Tools/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ static class Program
1313
static void Main(string[] args)
1414
{
1515
//address 2 script hash
16-
Console.WriteLine(Neo.Wallets.Wallet.ToScriptHash("AK4LdT5ZXR9DQZjfk5X6Xy79mE8ad8jKAW"));
16+
Console.WriteLine(Neo.Wallets.Wallet.ToScriptHash("Ae8AD6Rc3cvQapqttJcUTj9ULfLi2tLHmc"));
1717
//script hash 2 address
18-
Console.WriteLine(Neo.Wallets.Wallet.ToAddress(new UInt160("0x9121e89e8a0849857262d67c8408601b5e8e0524".Remove(0, 2).HexToBytes().Reverse().ToArray())));
18+
Console.WriteLine(Neo.Wallets.Wallet.ToAddress(new UInt160("0x505663a29d83663a838eee091249abd167e928f5".Remove(0, 2).HexToBytes().Reverse().ToArray())));
1919

2020
//hex string 2 string
2121
Console.WriteLine("7472616e73666572".HexToString());

UnitTests/CGASTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace UnitTests
1515
{
1616
public static class CGASTest
1717
{
18-
static readonly UInt160 SgasAddress = Wallet.ToScriptHash("AK4LdT5ZXR9DQZjfk5X6Xy79mE8ad8jKAW");
19-
static readonly UInt160 ScriptHash = new UInt160("0x9121e89e8a0849857262d67c8408601b5e8e0524".Remove(0, 2).HexToBytes().Reverse().ToArray());
18+
static readonly UInt160 SgasAddress = Wallet.ToScriptHash("Ae8AD6Rc3cvQapqttJcUTj9ULfLi2tLHmc");
19+
static readonly UInt160 ScriptHash = new UInt160("0x505663a29d83663a838eee091249abd167e928f5".Remove(0, 2).HexToBytes().Reverse().ToArray());
2020
static readonly UInt160 User = Wallet.ToScriptHash("AJd31a8rYPEBkY1QSxpsGy8mdU4vTYTD4U");
2121
static readonly byte[] UserScript = "2103ad1d70f140d84a90ad4491cdf175fa64bfa9287a006e8cbd8f8db8500b5205baac".HexToBytes();
2222

0 commit comments

Comments
 (0)