public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount, object data = null) { Assert(from.Length == 20, "The from address is invalid."); Assert(to.Length == 20, "The to address is invalid."); Assert(amount > 0, "The parameter amount must be greater than 0."); Assert(Runtime.CheckWitness(from) || from.Equals(Runtime.CallingScriptHash), "No authorization."); Assert(BalanceOf(from) >= amount, "Insufficient balance."); if (from == to) { return(true); } AssetReduce(from, amount); AssetIncrease(to, amount); OnTransfer(from, to, amount); // Validate payable if (ContractManagement.GetContract(to) != null) { Contract.Call(to, "onNEP17Payment", CallFlags.All, from, amount, data); } return(true); }
public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount, object data) { Assert(from.IsValid && to.IsValid, "Invalid From or To Address"); Assert(amount > 0, "The parameter amount MUST be greater than 0."); Assert(Runtime.CheckWitness(from), "No authorization."); var me = Runtime.ExecutingScriptHash; if (to == me) { Assert(CheckIsRouter(Runtime.CallingScriptHash), "Not Allowed To Transfer"); } Assert(AssetStorage.Get(from) >= amount, "Insufficient balance."); if (from == to) { return(true); } AssetStorage.Reduce(from, amount); AssetStorage.Increase(to, amount); onTransfer(from, to, amount); // Validate payable if (ContractManagement.GetContract(to) != null) { Contract.Call(to, "onNEP17Payment", CallFlags.All, new object[] { from, amount, data }); } return(true); }
public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount, object data) { if (amount <= 0) { throw new Exception("The parameter amount MUST be greater than 0."); } if (!Runtime.CheckWitness(from) && !from.Equals(ExecutionEngine.CallingScriptHash)) { throw new Exception("No authorization."); } if (AssetStorage.Get(from) < amount) { throw new Exception("Insufficient balance."); } if (from == to) { return(true); } AssetStorage.Reduce(from, amount); AssetStorage.Increase(to, amount); OnTransfer(from, to, amount); // Validate payable if (ContractManagement.GetContract(to) != null) { Contract.Call(to, "onNEP17Payment", CallFlags.All, new object[] { from, amount, data }); } return(true); }
private static void PostTransfer(UInt160 from, UInt160 to, ByteString tokenId, object data) { OnTransfer(from, to, 1, tokenId); if (to is not null && ContractManagement.GetContract(to) is not null) { Contract.Call(to, "onNEP11Payment", CallFlags.All, from, 1, tokenId, data); } }
protected static void PostTransfer(UInt160 from, UInt160 to, BigInteger amount, object data) { OnTransfer(from, to, amount); if (to is not null && ContractManagement.GetContract(to) is not null) { Contract.Call(to, "onNEP17Payment", CallFlags.All, from, amount, data); } }
public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount, object data = null) { if (IsPaused()) { Error("System is paused."); return(false); } if (IsBlacklisted(from)) { Error("Argument from is in blacklist."); return(false); } if (IsBlacklisted(to)) { Error("Argument to is in blacklist."); return(false); } if (amount <= 0) { Error("The parameter amount MUST be greater than 0."); return(false); } if (!Runtime.CheckWitness(from)) { Error("No authorization."); return(false); } if (AssetStorage.Get(from) < amount) { Error("Insufficient balance."); return(false); } if (from == to) { return(true); } AssetStorage.Reduce(from, amount); AssetStorage.Increase(to, amount); Transferred(from, to, amount); if (ContractManagement.GetContract(to) != null) { Contract.Call(to, "onPayment", CallFlags.ReadOnly, new object[] { from, amount, data }); } return(true); }
public static object ManagementTest(UInt160 hash) { OnNotify(ContractManagement.Hash); OnNotify(ContractManagement.Name); OnNotify(ContractManagement.GetContract(hash).Hash); OnNotify(ContractManagement.GetContract(hash).Id); OnNotify(ContractManagement.GetContract(hash).Nef); OnNotify(ContractManagement.GetContract(hash).UpdateCounter); return(ContractManagement.GetContract(hash).Manifest); }
public static bool Migrate(UInt160 script, string manifest) { if (!IsPaused()) { Error("System is not paused."); return(false); } if (!IsAdmin()) { Error("No authorization."); return(false); } if (script != null && script.Equals(ContractManagement.GetContract(Runtime.ExecutingScriptHash))) { return(true); } ContractManagement.Update(script, manifest); return(true); }
/// <summary> /// 增加nep17资产的exchange合约映射 /// </summary> /// <param name="exchangeContractHash"></param> /// <returns></returns> public static bool RegisterExchangePair(UInt160 exchangeContractHash) { Assert(Runtime.CheckWitness(GetAdmin()), "Forbidden"); var contract = ContractManagement.GetContract(exchangeContractHash); Assert(contract != null, "Not Deployed"); var token0 = (UInt160)Contract.Call(exchangeContractHash, "getToken0", CallFlags.ReadOnly, new object[0]); var token1 = (UInt160)Contract.Call(exchangeContractHash, "getToken1", CallFlags.ReadOnly, new object[0]); Assert(token0 != null && token1 != null, "Token Invalid"); var key = GetPairKey(token0, token1); //var value = StorageGet(key); //if (value != null) //{ // onRemoveExchange(token0, token1); //} StoragePut(key, exchangeContractHash); onCreateExchange(token0, token1, exchangeContractHash); return(true); }
private static bool IsDeployed(UInt160 address) => ContractManagement.GetContract(address) != null;
public static object GetContract(UInt160 hash, string whatReturn) { var contract = ContractManagement.GetContract(hash); return(GetContractInfo(contract, whatReturn)); }
public static string NewContract() { return(ContractManagement.GetContract(Runtime.ExecutingScriptHash).Manifest.Name); }
public static string OldContract(byte[] nefFile, string manifest) { ContractManagement.Update((ByteString)nefFile, manifest, null); return ContractManagement.GetContract(Runtime.ExecutingScriptHash).Manifest.Name; }