private static bool NEP5transfer(byte[] from, byte[] to, byte[] assetHash, BigInteger amount) { StorageMap balanceMap = Storage.CurrentContext.CreateMap("balanceMap"); assetSetting assetSetting = getAssetSetting(assetHash); //多判断总比少判断好 if (amount <= 0) { throw new InvalidOperationException("error"); } if (from.Length != 20 || to.Length != 20) { throw new InvalidOperationException("error"); } //构造入参 object[] transInput = new object[3]; transInput[0] = from; transInput[1] = to; transInput[2] = amount; //动态调用执行转账 deleDyncall dyncall = (deleDyncall)assetHash.ToDelegate(); bool result = (bool)dyncall(assetSetting.appTransferMethod, transInput); return(result); }
/** * 使用txid充值 */ public static bool rechargeToken(byte[] owner, byte[] txid) { if (owner.Length != 20) { Runtime.Log("Owner error."); return(false); } //2018/6/5 cwt 修补漏洞 byte[] keytxid = new byte[] { 0x11 }.Concat(txid); byte[] keytowner = new byte[] { 0x11 }.Concat(owner); byte[] txinfo = Storage.Get(Storage.CurrentContext, keytxid); if (txinfo.Length > 0) { // 已经处理过了 return(false); } // 查询交易记录 object[] args = new object[1] { txid }; byte[] sgasHash = Storage.Get(Storage.CurrentContext, "sgas"); deleDyncall dyncall = (deleDyncall)sgasHash.ToDelegate(); object[] res = (object[])dyncall("getTXInfo", args); if (res.Length > 0) { byte[] from = (byte[])res[0]; byte[] to = (byte[])res[1]; BigInteger value = (BigInteger)res[2]; if (from == owner) { if (to == ExecutionEngine.ExecutingScriptHash) { // 标记为处理 Storage.Put(Storage.CurrentContext, keytxid, value); BigInteger nMoney = 0; byte[] ownerMoney = Storage.Get(Storage.CurrentContext, owner); if (ownerMoney.Length > 0) { nMoney = ownerMoney.AsBigInteger(); } nMoney += value; _addTotal(value); // 记账 Storage.Put(Storage.CurrentContext, keytowner, nMoney.AsByteArray()); return(true); } } } return(false); }
public static OwnerInfo GetOwnerInfo(byte[] fullHash) { deleDyncall centerCall = (deleDyncall)getSysSetting("domainCenterHash").ToDelegate(); var ownerInfo = centerCall("getOwnerInfo", new object[1] { fullHash }) as OwnerInfo; return(ownerInfo); }
/** * 提币 */ public static bool drawToken(byte[] sender, BigInteger count) { if (sender.Length != 20) { Runtime.Log("Owner error."); return(false); } //2018/6/5 cwt 修补漏洞 byte[] keytsender = new byte[] { 0x11 }.Concat(sender); if (Runtime.CheckWitness(sender)) { BigInteger nMoney = 0; byte[] ownerMoney = Storage.Get(Storage.CurrentContext, keytsender); if (ownerMoney.Length > 0) { nMoney = ownerMoney.AsBigInteger(); } if (count <= 0 || count > nMoney) { // 全部提走 count = nMoney; } // 转账 object[] args = new object[3] { ExecutionEngine.ExecutingScriptHash, sender, count }; byte[] sgasHash = Storage.Get(Storage.CurrentContext, "sgas"); deleDyncall dyncall = (deleDyncall)sgasHash.ToDelegate(); bool res = (bool)dyncall("transfer_app", args); if (!res) { return(false); } // 记账 nMoney -= count; _subTotal(count); if (nMoney > 0) { Storage.Put(Storage.CurrentContext, keytsender, nMoney.AsByteArray()); } else { Storage.Delete(Storage.CurrentContext, keytsender); } return(true); } return(false); }
/** * 提币 */ public static bool drawToken(byte[] sender, BigInteger count) { if (sender.Length != 20) { Runtime.Log("Owner error."); return(false); } //2018/6/5 cwt 修补漏洞 byte[] keytsender = new byte[] { 0x11 }.Concat(sender); if (Runtime.CheckWitness(sender)) { BigInteger nMoney = 0; //byte[] ownerMoney = Storage.Get(Storage.CurrentContext, keytsender); UserInfo userInfo = getUserInfo(sender); nMoney = userInfo.balance; if (count <= 0 || count > nMoney) { // 全部提走 count = nMoney; } // 转账 object[] args = new object[4] { ExecutionEngine.ExecutingScriptHash, sender, count, ExecutionEngine.ExecutingScriptHash }; byte[] sgasHash = Storage.Get(Storage.CurrentContext, "sgas"); deleDyncall dyncall = (deleDyncall)sgasHash.ToDelegate(); bool res = (bool)dyncall("transfer", args); if (!res) { return(false); } // 记账 nMoney -= count; _subTotal(count); if (nMoney > 0) { userInfo.balance = nMoney; Storage.Put(Storage.CurrentContext, keytsender, Helper.Serialize(userInfo)); } else { Storage.Delete(Storage.CurrentContext, keytsender); } return(true); } return(false); }
/** * 将收入提款到合约拥有者 */ public static bool drawToContractOwner(BigInteger flag, BigInteger count) { if (Runtime.CheckWitness(ContractOwner)) { BigInteger nMoney = 0; // 查询余额 object[] args = new object[1] { ExecutionEngine.ExecutingScriptHash }; byte[] sgasHash = Storage.Get(Storage.CurrentContext, "sgas"); deleDyncall dyncall = (deleDyncall)sgasHash.ToDelegate(); BigInteger totalMoney = (BigInteger)dyncall("balanceOf", args); BigInteger supplyMoney = Storage.Get(Storage.CurrentContext, "totalExchargeSgas").AsBigInteger(); if (flag == 0) { BigInteger canDrawMax = totalMoney - supplyMoney; if (count <= 0 || count > canDrawMax) { // 全部提走 count = canDrawMax; } } else { //由于官方SGAS合约实在太慢,为了保证项目上线,先发行自己的SGAS合约方案,预留出来迁移至官方sgas用的。 count = totalMoney; nMoney = 0; Storage.Put(Storage.CurrentContext, "totalExchargeSgas", nMoney); } // 转账 args = new object[3] { ExecutionEngine.ExecutingScriptHash, ContractOwner, count }; deleDyncall dyncall2 = (deleDyncall)sgasHash.ToDelegate(); bool res = (bool)dyncall2("transferAPP", args); if (!res) { return(false); } // 记账 cwt此处不应该记账 //_subTotal(count); return(true); } return(false); }
public static BigInteger getAuctionAllFee() { BigInteger nMoney = 0; // 查询余额 object[] args = new object[1] { ExecutionEngine.ExecutingScriptHash }; byte[] sgasHash = Storage.Get(Storage.CurrentContext, "sgas"); deleDyncall dyncall = (deleDyncall)sgasHash.ToDelegate(); BigInteger totalMoney = (BigInteger)dyncall("balanceOf", args); BigInteger supplyMoney = Storage.Get(Storage.CurrentContext, "totalExchargeSgas").AsBigInteger(); BigInteger canDrawMax = totalMoney - supplyMoney; return(canDrawMax); }
static TransferInfo getTxIn(byte[] txid, byte[] assetHash) { StorageMap txidVerifiedMap = Storage.CurrentContext.CreateMap("txidVerifiedMap"); if (txidVerifiedMap.Get(txid).AsBigInteger() == 0)//如果這個交易已經處理過,就當get不到 { object[] _p = new object[1]; _p[0] = txid; deleDyncall dyncall = (deleDyncall)assetHash.ToDelegate(); var info = dyncall("getTxInfo", _p); if (((object[])info).Length == 3) { return(info as TransferInfo); } } var tInfo = new TransferInfo(); tInfo.from = new byte[0]; return(tInfo); }
public static bool TransferIn(byte[] from, byte[] assetHash, BigInteger value) { //验证from的权限 if (!Runtime.CheckWitness(from)) { throw new InvalidOperationException("error"); } if (value < 0) { throw new InvalidOperationException("error"); } //明确to是本合约 byte[] to = ExecutionEngine.ExecutingScriptHash; //获取转入资产的信息 deleDyncall dyncall = (deleDyncall)assetHash.ToDelegate(); object[] _p = new object[3]; _p[0] = from; _p[1] = to; _p[2] = value; if (!(bool)dyncall("transfer", _p))//转账失败 { throw new Exception("param is wrong"); } StorageMap txidVerifiedMap = Storage.CurrentContext.CreateMap("txidVerifiedMap"); StorageMap balanceMap = Storage.CurrentContext.CreateMap("balanceMap"); //存錢 byte[] txid = (ExecutionEngine.ScriptContainer as Transaction).Hash; var balance = balanceMap.Get(from.Concat(assetHash)).AsBigInteger(); balance += value; balanceMap.Put(from.Concat(assetHash), balance); onSetMoneyIn(from, assetHash, value, txid); //記錄這個txid處理過了,只處理一次 txidVerifiedMap.Put(txid, 1); return(true); }
/// <summary> /// 取消域名拍卖 /// </summary> /// <param name="fullhash"></param> /// <returns></returns> public static bool DiscontinueAuction(byte[] auctionid) { //获取域名的拍卖情况 StorageMap auctionInfoMap = Storage.CurrentContext.CreateMap("auctionInfoMap"); var bytes = auctionInfoMap.Get(auctionid); if (bytes.Length == 0) { throw new InvalidOperationException("error"); } AuctionInfo auctionInfo = bytes.Deserialize() as AuctionInfo; //验证权限 if (!Runtime.CheckWitness(auctionInfo.auctioner) && !checkSpuerAdmin()) { throw new InvalidOperationException("error"); } //将域名退回给卖家(域名所有权:DEX合约=>卖家) byte[] scriptHash = ExecutionEngine.ExecutingScriptHash; deleDyncall centerCall = (deleDyncall)getSysSetting("domainCenterHash").ToDelegate(); var result = (byte[])centerCall("owner_SetOwner", new object[3] { scriptHash, auctionInfo.fullHash, auctionInfo.auctioner }); //if (result.AsBigInteger() != 1) // throw new InvalidOperationException("error"); //归还押金 var mortgageAssetHash = getSysSetting("mortgageAssetHash"); StorageMap balanceMap = Storage.CurrentContext.CreateMap("balanceMap"); var balanceOfBuyer = balanceMap.Get(auctionInfo.auctioner.Concat(mortgageAssetHash)).AsBigInteger(); balanceOfBuyer = balanceOfBuyer + auctionInfo.mortgagePayments; balanceMap.Put(auctionInfo.auctioner.Concat(mortgageAssetHash), balanceOfBuyer); onDexTransfer(new byte[] { }, auctionInfo.auctioner, mortgageAssetHash, auctionInfo.mortgagePayments); auctionInfoMap.Delete(auctionid); onAuctionDiscontinued(auctionInfo); return(true); }
/** * 将收入提款到合约拥有者 */ public static bool drawToContractOwner(BigInteger count) { if (Runtime.CheckWitness(ContractOwner)) { BigInteger nMoney = 0; // 查询余额 object[] args = new object[1] { ExecutionEngine.ExecutingScriptHash }; byte[] sgasHash = Storage.Get(Storage.CurrentContext, "sgas"); deleDyncall dyncall = (deleDyncall)sgasHash.ToDelegate(); BigInteger totalMoney = (BigInteger)dyncall("balanceOf", args); BigInteger supplyMoney = Storage.Get(Storage.CurrentContext, "totalExchargeSgas").AsBigInteger(); BigInteger canDrawMax = totalMoney - supplyMoney; if (count <= 0 || count > canDrawMax) { // 全部提走 count = canDrawMax; } // 转账 args = new object[3] { ExecutionEngine.ExecutingScriptHash, ContractOwner, count }; deleDyncall dyncall2 = (deleDyncall)sgasHash.ToDelegate(); bool res = (bool)dyncall2("transfer_app", args); if (!res) { return(false); } // 记账 _subTotal(count); return(true); } return(false); }
/// <summary> /// 拍卖某个域名 /// </summary> /// <param name="domainArray"></param> /// <param name="startPrice"></param> /// <param name="endPrice"></param> /// <param name="ratio"></param> /// <returns></returns> public static bool Auction(string[] domainArray, byte[] assetHash, BigInteger startPrice, BigInteger endPrice, BigInteger salePrice, BigInteger mortgagePayments) { //不允许的资产不能定价 assetSetting assetSetting = getAssetSetting(assetHash); if (assetSetting.enable != 1) { throw new InvalidOperationException("error"); } //价格必须大于0 if (startPrice <= 0 || endPrice <= 0 || endPrice > startPrice) { throw new InvalidOperationException("error"); } //合约限制最小价格为0.1,并且小数点后面不能超过一位(按照精度2换算),NNC为10 if (startPrice < assetSetting.valueMin || startPrice % assetSetting.valueUnit > 0 || endPrice < assetSetting.valueMin || endPrice % assetSetting.valueUnit > 0) { throw new InvalidOperationException("error"); } //限制每次降价的精度 if ((salePrice < assetSetting.valueMin || salePrice % assetSetting.valueUnit > 0) && salePrice != 0) { throw new InvalidOperationException("error"); } //验证押金 BigInteger minMortgagePayments = getSysSetting("minMortgagePayments").AsBigInteger(); if (mortgagePayments < minMortgagePayments) { throw new InvalidOperationException("error"); } byte[] fullHash = NameHashArray(domainArray); //先获取这个域名的信息 OwnerInfo ownerInfo = GetOwnerInfo(fullHash); var auctioner = ownerInfo.owner; //域名没有初始化不能上架 if (ownerInfo.owner.Length == 0) { throw new InvalidOperationException("error"); } //域名已经到期了不能上架 if (!verifyExpires(ownerInfo.TTL)) { throw new InvalidOperationException("error"); } //验证权限 if (!Runtime.CheckWitness(auctioner)) { throw new InvalidOperationException("error"); } //将域名抵押给本合约(域名所有权:卖家=>DEX合约) //本合约的scripthash byte[] scriptHash = ExecutionEngine.ExecutingScriptHash; deleDyncall centerCall = (deleDyncall)getSysSetting("domainCenterHash").ToDelegate(); var result = (byte[])centerCall("owner_SetOwner", new object[3] { auctioner, fullHash, scriptHash }); if (result.AsBigInteger() != 1) { throw new InvalidOperationException("error"); } //扣除押金 var mortgageAssetHash = getSysSetting("mortgageAssetHash"); StorageMap balanceMap = Storage.CurrentContext.CreateMap("balanceMap"); var balanceOfBuyer = balanceMap.Get(auctioner.Concat(mortgageAssetHash)).AsBigInteger(); balanceOfBuyer = balanceOfBuyer - mortgagePayments; if (balanceOfBuyer > 0) { balanceMap.Put(auctioner.Concat(mortgageAssetHash), balanceOfBuyer); } else if (balanceOfBuyer == 0) { balanceMap.Delete(auctioner.Concat(mortgageAssetHash)); } else { throw new Exception("no money"); } onDexTransfer(auctioner, new byte[] { }, mortgageAssetHash, mortgagePayments); //获取开始拍卖的时间戳 var timeStamp = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; //获取交易id var auctionid = (ExecutionEngine.ScriptContainer as Transaction).Hash; //记录拍卖的信息 AuctionInfo auctionInfo = new AuctionInfo() { auctionid = auctionid, fullDomain = getFullStrForArray(domainArray), fullHash = fullHash, auctioner = auctioner, startPrice = startPrice, endPrice = endPrice, salePrice = salePrice, startTimeStamp = timeStamp, assetHash = assetHash, mortgagePayments = mortgagePayments, }; StorageMap auctionInfoMap = Storage.CurrentContext.CreateMap("auctionInfoMap"); //如果已经存在这个id报错 if (auctionInfoMap.Get(auctionid).Length != 0) { throw new Exception("error"); } auctionInfoMap.Put(auctionid, auctionInfo.Serialize()); //记录当前这个域名正在拍卖的场次是什么 StorageMap auctionInfoCurrentMap = Storage.CurrentContext.CreateMap("auctionInfoCurrentMap"); auctionInfoCurrentMap.Put(fullHash, auctionid); onAuction(auctionInfo); return(true); }
/// <summary> /// 出售 /// </summary> /// <param name="buyer">求购者</param> /// <param name="fullHash"></param> /// <param name="assetHash"></param> /// <returns></returns> public static bool Sell(byte[] offerid) { //获取求购信息 OfferToBuyInfo offerToBuyInfo = GetOfferToBuyInfo(offerid); if (offerToBuyInfo.fullHash.Length == 0)//没求购过别浪费时间了 { throw new InvalidOperationException("error"); } var fullHash = offerToBuyInfo.fullHash; var buyer = offerToBuyInfo.buyer; var assetHash = offerToBuyInfo.assetHash; //先获取这个域名的信息 OwnerInfo ownerInfo = GetOwnerInfo(fullHash); if (ownerInfo.owner.Length == 0 || !verifyExpires(ownerInfo.TTL))//验证域名是否有效 { throw new InvalidOperationException("error"); } //验证权限 var seller = ownerInfo.owner; if (!Runtime.CheckWitness(seller)) { throw new InvalidOperationException("error"); } //进行域名的转让操作(域名所有权:卖家=>买家) deleDyncall centerCall = (deleDyncall)getSysSetting("domainCenterHash").ToDelegate(); var result = (byte[])centerCall("owner_SetOwner", new object[3] { seller, fullHash, buyer }); if (result.AsBigInteger() != 1) //如果域名所有权转移失败,返回失败 { throw new InvalidOperationException("error"); } //把钱转给卖家 assetSetting assetSetting = getAssetSetting(assetHash); BigInteger handlingFee = offerToBuyInfo.price * assetSetting.handlingFeeRate / fixedNumber; //handlingFeeRate是事先乘10000存储的 StorageMap balanceMap = Storage.CurrentContext.CreateMap("balanceMap"); var balanceOfSeller = balanceMap.Get(seller.Concat(assetHash)).AsBigInteger(); //卖家 balanceOfSeller = balanceOfSeller + offerToBuyInfo.price - handlingFee; //给卖方增加钱(扣除手续费) balanceMap.Put(seller.Concat(assetHash), balanceOfSeller); onDexTransfer(new byte[] { }, seller, assetHash, offerToBuyInfo.price - handlingFee); //转移手续费 //发送手续费到分红池 if (handlingFee > 0) { if (!NEP5transfer(ExecutionEngine.ExecutingScriptHash, getSysSetting("dividingPoolAddr"), assetHash, handlingFee)) { throw new Exception("NEP5transfer is wrong"); } } //把押金还给买家 var mortgageAssetHash = getSysSetting("mortgageAssetHash"); var nncBalanceOfOffer = balanceMap.Get(buyer.Concat(mortgageAssetHash)).AsBigInteger(); nncBalanceOfOffer += offerToBuyInfo.mortgagePayments; balanceMap.Put(buyer.Concat(mortgageAssetHash), nncBalanceOfOffer); onDexTransfer(new byte[] { }, buyer, mortgageAssetHash, offerToBuyInfo.mortgagePayments); //删除此条求购信息 DeleteOfferToBuyInfo(offerid); //通知 onSell(seller, offerToBuyInfo); return(true); }
/// <summary> /// 竞拍 /// </summary> /// <param name="fullHash"></param> /// <param name="price">价格,价格合约内计算,但是要求传入是以防前端计算错误误导用户</param> /// <returns></returns> public static bool Bet(byte[] buyer, byte[] auctionid, byte[] assetHash, BigInteger price) { if (!Runtime.CheckWitness(buyer)) { throw new InvalidOperationException("error"); } //获取域名的拍卖情况 AuctionInfo auctionInfo = GetAuctionInfo(auctionid); //自己不能竞拍自己上架的域名 if (buyer == auctionInfo.auctioner) { throw new InvalidOperationException("error"); } if (auctionInfo.fullDomain == "") { throw new InvalidOperationException("error"); } //验证资产种类 if (auctionInfo.assetHash != assetHash) { throw new InvalidOperationException("error"); } //获取当前的时间戳 var currentTimeStamp = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; //距离开始拍卖已经过了多久 var timeStamp = currentTimeStamp - auctionInfo.startTimeStamp; //获取降价的间隔 var interval = getSysSetting("interval").AsBigInteger(); //X小时一轮 开拍为0阶段 X小时后为1阶段 X*2小时后为2阶段 X*60*60 var phase = timeStamp / interval; //计算当前的价格 var currentPrice = auctionInfo.startPrice - auctionInfo.salePrice * phase; if (currentPrice < auctionInfo.endPrice) { currentPrice = auctionInfo.endPrice; } //对比下用户从前端获取到的价格 if (price != currentPrice) { throw new InvalidOperationException("error"); } //检查用户钱够不够 StorageMap balanceMap = Storage.CurrentContext.CreateMap("balanceMap"); var balanceOfBuyer = balanceMap.Get(buyer.Concat(assetHash)).AsBigInteger();//买家 if (balanceOfBuyer < price) { throw new InvalidOperationException("error"); } //合约将域名转让给买家 byte[] scriptHash = ExecutionEngine.ExecutingScriptHash; deleDyncall centerCall = (deleDyncall)getSysSetting("domainCenterHash").ToDelegate(); var result = (byte[])centerCall("owner_SetOwner", new object[3] { scriptHash, auctionInfo.fullHash, buyer }); if (result.AsBigInteger() != 1) { throw new InvalidOperationException("error"); } //购买者扣钱 balanceOfBuyer = balanceOfBuyer - price; if (balanceOfBuyer == 0) { balanceMap.Delete(buyer.Concat(assetHash)); } else { balanceMap.Put(buyer.Concat(assetHash), balanceOfBuyer); } onDexTransfer(buyer, new byte[] { }, assetHash, price); //转钱给拍卖者 //计算手续费 assetSetting assetSetting = getAssetSetting(assetHash); BigInteger handlingFee = price * assetSetting.handlingFeeRate / fixedNumber;//handlingFeeRate是事先乘10000存储的 //给卖方增加钱(扣除手续费) var auctioner = auctionInfo.auctioner; var balanceOfAuctioner = balanceMap.Get(auctioner.Concat(assetHash)).AsBigInteger(); balanceMap.Put(auctioner.Concat(assetHash), balanceOfAuctioner + price - handlingFee); onDexTransfer(new byte[] { }, auctioner, assetHash, price - handlingFee); //归还卖方的抵押金 var mortgageAssetHash = getSysSetting("mortgageAssetHash"); var nncBalanceOfAuctioner = balanceMap.Get(auctioner.Concat(mortgageAssetHash)).AsBigInteger(); balanceMap.Put(auctioner.Concat(mortgageAssetHash), nncBalanceOfAuctioner + auctionInfo.mortgagePayments); onDexTransfer(new byte[] { }, auctioner, mortgageAssetHash, auctionInfo.mortgagePayments); if (handlingFee > 0) { if (!NEP5transfer(ExecutionEngine.ExecutingScriptHash, getSysSetting("dividingPoolAddr"), assetHash, handlingFee)) { throw new Exception("NEP5transfer is wrong"); } } //删除拍卖信息 StorageMap auctionInfoMap = Storage.CurrentContext.CreateMap("auctionInfoMap"); auctionInfoMap.Delete(auctionid); onBet(auctionInfo, buyer, price); return(true); }
public static object Main(string method, object[] args) { string magicstr = "for nns test 002"; if (method == "_setTarget") { if (Runtime.CheckWitness(superAdmin)) { Storage.Put(Storage.CurrentContext, "target", (byte[])args[0]); return(new byte[] { 0x01 }); } return(new byte[] { 0x00 }); } var callscript = ExecutionEngine.CallingScriptHash; byte[] target = Storage.Get(Storage.CurrentContext, "target"); #region 所有者接口 直接调用&智能合约 if (method == "owner_SetOwner") { object[] newarg = new object[4]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } if (method == "owner_SetRegister") { object[] newarg = new object[4]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } if (method == "owner_SetResolver") { object[] newarg = new object[4]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } #endregion #region 注册器接口 仅智能合约 if (method == "register_SetSubdomainOwner") { object[] newarg = new object[5]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; newarg[4] = args[3]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } #endregion #region 升级合约,耗费990(有动态调用),仅限管理员 if (method == "migrate") { //不是管理员 不能操作 if (!Runtime.CheckWitness(superAdmin)) { return(false); } if (args.Length != 1 && args.Length != 9) { return(false); } byte[] script = Blockchain.GetContract(ExecutionEngine.ExecutingScriptHash).Script; byte[] new_script = (byte[])args[0]; //如果传入的脚本一样 不继续操作 if (script == new_script) { return(false); } byte[] parameter_list = new byte[] { 0x07, 0x10 }; byte return_type = 0x05; bool need_storage = (bool)(object)03; string name = "domaincenter_jump"; string version = "1"; string author = "xx"; string email = "xx"; string description = "域名跳板合约"; if (args.Length == 9) { parameter_list = (byte[])args[1]; return_type = (byte)args[2]; need_storage = (bool)args[3]; name = (string)args[4]; version = (string)args[5]; author = (string)args[6]; email = (string)args[7]; description = (string)args[8]; } Contract.Migrate(new_script, parameter_list, return_type, need_storage, name, version, author, email, description); return(true); } #endregion deleDyncall _dyncall = (deleDyncall)target.ToDelegate(); return(_dyncall(method, args)); }
public static object Main(string method, object[] args) { string magicstr = "for nns test 002"; if (method == "_setTarget") { if (Runtime.CheckWitness(superAdmin)) { Storage.Put(Storage.CurrentContext, "target", (byte[])args[0]); return(new byte[] { 0x01 }); } return(new byte[] { 0x00 }); } var callscript = ExecutionEngine.CallingScriptHash; byte[] target = Storage.Get(Storage.CurrentContext, "target"); #region 所有者接口 直接调用&智能合约 if (method == "owner_SetOwner") { object[] newarg = new object[4]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } if (method == "owner_SetRegister") { object[] newarg = new object[4]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } if (method == "owner_SetResolver") { object[] newarg = new object[4]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } #endregion #region 注册器接口 仅智能合约 if (method == "register_SetSubdomainOwner") { object[] newarg = new object[5]; newarg[0] = callscript; newarg[1] = args[0]; newarg[2] = args[1]; newarg[3] = args[2]; newarg[4] = args[3]; deleDyncall dyncall = (deleDyncall)target.ToDelegate(); return(dyncall(method, newarg)); } #endregion deleDyncall _dyncall = (deleDyncall)target.ToDelegate(); return(_dyncall(method, args)); }