public static object TransferApp(byte[] assetid, byte[] to, BigInteger amount) { object[] _p = new object[3] { ExecutionEngine.ExecutingScriptHash, to, amount }; deleCall call = (deleCall)assetid.ToDelegate(); return(call("transfer_app", _p)); }
public static TransferInfo GetTxInfo(byte[] assetid, byte[] txid) { StorageMap txInfoMap = Storage.CurrentContext.CreateMap("txInfoMap"); var tInfo = new TransferInfo(); var v = txInfoMap.Get(txid).AsBigInteger(); if (v == 0) { object[] _p = new object[1] { txid }; deleCall call = (deleCall)assetid.ToDelegate(); var info = call("getTxInfo", _p); if (((object[])info).Length == 3) { return(info as TransferInfo); } } return(tInfo); }
public static object Main(string method, object[] args) { string magicStr = "BancorManager"; if (Runtime.Trigger == TriggerType.Verification) { return(false); } else if (Runtime.Trigger == TriggerType.Application) { var callscript = ExecutionEngine.CallingScriptHash; //invoke if ("name" == method) { return(Name()); } if ("getWhiteList" == method) { return(GetWhiteList()); } if ("getMathContract" == method) { return(GetMathContract()); } //需要管理员权限调用 if ("setMathContract" == method) { return(SetMathContract((byte[])args[0])); } if ("setWhiteList" == method) { return(SetWhiteList((byte[])args[0], (string)args[1])); } //转发的方法 //不在白名单的合约不准跳板 Map <byte[], string> map = GetWhiteList(); if (!map.HasKey(callscript)) { return(true); } byte[] mathContract = GetMathContract(); if (mathContract.Length == 0) { return(true); } deleCall call = (deleCall)mathContract.ToDelegate(); if ("purchase" == method) { return(call(method, args)); } if ("sale" == method) { return(call(method, args)); } //未知方法 也全部去转发 return(call(method, args)); } return(true); }
public static object Main(string method, object[] args) { var magicstr = "Test_Contract_v0.35"; if (Runtime.Trigger == TriggerType.Application) { var callscript = ExecutionEngine.CallingScriptHash; if (method == "witnessTest") { Notify(new byte[] { }, 0); if (!Runtime.CheckWitness((byte[])args[0])) { return(false); } Notify((byte[])args[0], 1); if (!Runtime.CheckWitness((byte[])args[1])) { return(false); } Notify((byte[])args[1], 2); } if (method == "set") { byte[] key = (byte[])args[0]; byte[] data = (byte[])args[1]; Storage.Put(Storage.CurrentContext, key, data); } if (method == "get") { byte[] key = (byte[])args[0]; return(Storage.Get(Storage.CurrentContext, key)); } if (method == "test") { return(1); } if (method == "call") { return("yes"); } if (method == "return") { byte[] asset_id = (byte[])args[0]; return(asset_id); } if (method == "getheight") { return(Blockchain.GetHeight()); } if (method == "getheader") { var height = (uint)args[0]; return(Blockchain.GetHeader(height)); } if (method == "strToByte") { var result = "hello world".AsByteArray(); return(result); } if (method == "balanceOf") { byte[] asset_id = (byte[])args[0]; byte[] address = (byte[])args[1]; var aa = NativeAsset.Call("BalanceOf", asset_id, address); return(aa); } if (method == "balanceOf1") { var asset_id = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] address = (byte[])args[0]; var aa = NativeAsset.Call("BalanceOf", asset_id, address).AsBigInteger(); return(aa); } if (method == "transferFrom") { byte[] asset_id = (byte[])args[0]; byte[] from = (byte[])args[1]; byte[] to = (byte[])args[2]; BigInteger value = (BigInteger)args[3]; var para = new object[3] { from, to, value }; deleCall contract = (deleCall)asset_id.ToDelegate(); var aa = (bool)contract("transferFrom", para); Runtime.Notify(1, aa); var par = new object[2] { from, to }; BigInteger ba = (BigInteger)contract("allowance", par); Runtime.Notify(1, ba); } if (method == "transferFrom1") { byte[] asset_id = (byte[])args[0]; byte[] from = (byte[])args[1]; byte[] to = (byte[])args[2]; BigInteger value = (BigInteger)args[3]; var success = NativeAsset.Call("TransferFrom", asset_id, from, to, value); Runtime.Notify(1, success); var par = new object[3] { asset_id, from, to }; BigInteger ba = NativeAsset.Call("Allowance", par).AsBigInteger(); Runtime.Notify(1, ba); } if (method == "transferApp") { byte[] asset_id = (byte[])args[0]; byte[] to = (byte[])args[1]; BigInteger value = (BigInteger)args[2]; byte[] from = ExecutionEngine.ExecutingScriptHash; var para = new object[3] { from, to, value }; var contract = (deleCall)asset_id.ToDelegate(); var aa = (bool)contract("transferApp", para); Runtime.Notify(from, to, value); Runtime.Notify(1, aa); } if (method == "GetTransferLog") { byte[] asset_id = (byte[])args[0]; byte[] txid = (byte[])args[1]; var tInfo = new TransferInfo(); var info = NativeAsset.Call("GetTransferLog", asset_id, txid); return(info); } if (method == "GetTransferLog3") { byte[] asset_id = (byte[])args[0]; byte[] txid = (byte[])args[1]; var tInfo = new TransferInfo(); var info = NativeAsset.GetTransferLog(asset_id, txid); return(info.Value); } } return(false); }
public static object Main(string method, object[] args) { string magicStr = "BancorCommon_v1.0"; if (Runtime.Trigger == TriggerType.Verification) { return(false); } else if (Runtime.Trigger == TriggerType.Application) { var callscript = ExecutionEngine.CallingScriptHash; //invoke if (method == "getWhiteList") { return(GetWhiteList()); } if (method == "getAssetInfo") { byte[] assetid = (byte[])args[0]; return(GetAssetInfo(assetid)); } //总管理员权限 if (method == "setMathContract") { if (!Runtime.CheckWitness(superAdmin)) { return(false); } return(SetMathContract((byte[])args[0])); } if (method == "setWhiteList") { if (!Runtime.CheckWitness(superAdmin)) { return(false); } var assetid = (byte[])args[0]; var connectAssetId = (byte[])args[1]; var admin = (byte[])args[2]; if (assetid.Length == 0 || connectAssetId.Length == 0 || admin.Length == 0) { return(false); } var whiteList = GetWhiteList(); AssetInfo assetInfo = new AssetInfo(); if (whiteList.HasKey(assetid)) //设置过就不能改了 { return(false); } assetInfo.connectAssetId = connectAssetId; assetInfo.admin = admin; if (SetAssetInfo(assetid, assetInfo)) { return(SetWhiteList(assetid, admin)); } return(false); } //应用币管理员权限 if (method == "setConnectWeight") { var assetid = (byte[])args[0]; var connectWeight = (BigInteger)args[1]; if (assetid.Length == 0 || connectWeight <= 0) { return(false); } var assetInfo = GetAssetInfo(assetid); if (!Runtime.CheckWitness(assetInfo.admin)) { return(false); } assetInfo.connectWeight = connectWeight; return(SetAssetInfo(assetid, assetInfo)); } if (method == "setMaxConnectWeight") { var assetid = (byte[])args[0]; var maxConnectWeight = (BigInteger)args[1]; if (assetid.Length == 0 || maxConnectWeight <= 0) { return(false); } var assetInfo = GetAssetInfo(assetid); if (!Runtime.CheckWitness(assetInfo.admin)) { return(false); } assetInfo.maxConnectWeight = maxConnectWeight; return(SetAssetInfo(assetid, assetInfo)); } if (method == "setConnectBalanceIn") { var assetid = (byte[])args[0]; var txid = (byte[])args[1]; var assetInfo = GetAssetInfo(assetid); if (!Runtime.CheckWitness(assetInfo.admin)) { return(false); } if (assetid.Length == 0 || txid.Length == 0 || assetInfo.connectAssetId.Length == 0) { return(false); } var tx = GetTxInfo(assetInfo.connectAssetId, txid); if (tx.from.AsBigInteger() != assetInfo.admin.AsBigInteger() || tx.to.AsBigInteger() != ExecutionEngine.ExecutingScriptHash.AsBigInteger() || tx.value <= 0) { return(false); } assetInfo.connectBalance += tx.value; if (SetAssetInfo(assetid, assetInfo)) { SetTxUsed(txid); return(true); } return(false); } if (method == "setSmartTokenSupplyIn") { var assetid = (byte[])args[0]; var txid = (byte[])args[1]; if (assetid.Length == 0 || txid.Length == 0) { return(false); } var assetInfo = GetAssetInfo(assetid); if (!Runtime.CheckWitness(assetInfo.admin)) { return(false); } var tx = GetTxInfo(assetid, txid); if (tx.from.AsBigInteger() != assetInfo.admin.AsBigInteger() || tx.to.AsBigInteger() != ExecutionEngine.ExecutingScriptHash.AsBigInteger() || tx.value <= 0) { return(false); } assetInfo.smartTokenSupply += tx.value; if (SetAssetInfo(assetid, assetInfo)) { SetTxUsed(txid); return(true); } return(false); } if (method == "getConnectBalanceBack") { var assetid = (byte[])args[0]; BigInteger amount = (BigInteger)args[1]; var assetInfo = GetAssetInfo(assetid); if (!Runtime.CheckWitness(assetInfo.admin)) { return(false); } if (assetid.Length == 0 || assetInfo.connectAssetId.Length == 0 || amount <= 0 || assetInfo.connectBalance < amount) { return(false); } if ((bool)TransferApp(assetInfo.connectAssetId, assetInfo.admin, amount)) { assetInfo.connectBalance -= amount; return(SetAssetInfo(assetid, assetInfo)); } return(false); } if (method == "getSmartTokenSupplyBack") { var assetid = (byte[])args[0]; BigInteger amount = (BigInteger)args[1]; var assetInfo = GetAssetInfo(assetid); if (!Runtime.CheckWitness(assetInfo.admin)) { return(false); } if (assetid.Length == 0 || amount <= 0 || assetInfo.smartTokenSupply < amount) { return(false); } if ((bool)TransferApp(assetid, assetInfo.admin, amount)) { assetInfo.smartTokenSupply -= amount; return(SetAssetInfo(assetid, assetInfo)); } return(false); } byte[] mathContract = GetMathContract(); if (mathContract.Length == 0) { return(true); } if (method == "getMathContract") { return(GetMathContract()); } if (method == "calculatePurchaseReturn") { var assetid = (byte[])args[0]; var amount = (BigInteger)args[1]; var assetInfo = GetAssetInfo(assetid); if (amount == 0 || assetInfo.connectBalance == 0 || assetInfo.smartTokenSupply == 0 || assetInfo.connectWeight == 0) { return(0); } deleCall mathCall = (deleCall)mathContract.ToDelegate(); return(mathCall("purchase", new object[5] { amount, assetInfo.connectBalance, assetInfo.smartTokenSupply, assetInfo.connectWeight, assetInfo.maxConnectWeight })); } //无需管理员权限 //转入一定的抵押币换取智能代币 if (method == "purchase") { var assetid = (byte[])args[0]; var txid = (byte[])args[1]; if (assetid.Length == 0 || txid.Length == 0) { return(false); } var assetInfo = GetAssetInfo(assetid); var tx = GetTxInfo(assetInfo.connectAssetId, txid); if (tx.from.Length == 0 || tx.to.AsBigInteger() != ExecutionEngine.ExecutingScriptHash.AsBigInteger() || tx.value <= 0) { return(false); } deleCall mathCall = (deleCall)mathContract.ToDelegate(); var amount = (BigInteger)mathCall("purchase", new object[5] { tx.value, assetInfo.connectBalance, assetInfo.smartTokenSupply, assetInfo.connectWeight, assetInfo.maxConnectWeight }); if ((bool)TransferApp(assetid, tx.from, amount)) { assetInfo.connectBalance += tx.value; assetInfo.smartTokenSupply -= amount; SetAssetInfo(assetid, assetInfo); SetTxUsed(txid); return(true); } return(false); } //清算一定的智能代币换取抵押币 if (method == "sale") { var assetid = (byte[])args[0]; var txid = (byte[])args[1]; if (assetid.Length == 0 || txid.Length == 0) { return(false); } var assetInfo = GetAssetInfo(assetid); var tx = GetTxInfo(assetid, txid); if (tx.from.Length == 0 || tx.to.AsBigInteger() != ExecutionEngine.ExecutingScriptHash.AsBigInteger() || tx.value <= 0) { return(false); } deleCall mathCall = (deleCall)mathContract.ToDelegate(); var amount = (BigInteger)mathCall("sale", new object[5] { tx.value, assetInfo.connectBalance, assetInfo.smartTokenSupply, assetInfo.connectWeight, assetInfo.maxConnectWeight }); if ((bool)TransferApp(assetInfo.connectAssetId, tx.from, amount)) { assetInfo.smartTokenSupply += tx.value; assetInfo.connectBalance -= amount; SetAssetInfo(assetid, assetInfo); SetTxUsed(txid); return(true); } return(false); } } return(false); }