// 根据其他账户的售卖挂单,进行交易 private static bool CancleSale(byte[] from, BigInteger sid) { //Check parameters if (from.Length != 20) { throw new InvalidOperationException("The parameters from and to SHOULD be 20-byte addresses."); } if (!Runtime.CheckWitness(from)) //0.2 { return(false); } StorageMap saleMul = Storage.CurrentContext.CreateMap(nameof(saleMul)); byte[] smFrom = saleMul.Get(from); // 如果from名下没有任何售卖单返回错误 if (smFrom == null || smFrom.Length == 0) { CancleMulSaleErr(from, sid, 10013); return(false); } Map <BigInteger, SaleMulInfo> sitems = Helper.Deserialize(smFrom) as Map <BigInteger, SaleMulInfo>; // 如果from名下没有该单号返回错误 if (!sitems.HasKey(sid)) { CancleMulSaleErr(from, sid, 10013); return(false); } SaleMulInfo s = sitems[sid]; object[] objs = new object[12]; objs[0] = ExecutionEngine.ExecutingScriptHash; objs[1] = from; objs[2] = s.count; for (int i = 0; i < s.count; i++) { objs[i + 3] = s.ids[i]; } // -----------调用EasyNFT 转移资产 if (NFTtransfer("transfer", objs) == false) { throw new Exception("NFTtransfer Fail!"); } //---------- // 删除该挂单 sitems.Remove(sid); saleMul.Put(from, Helper.Serialize(sitems)); CancleMulSaled(from, sid); return(true); }
// 根据其他账户的售卖挂单,进行交易 private static bool BuyFromOther(byte[] saler, byte[] buyer, BigInteger sid) { //Check parameters if (buyer.Length != 20) { throw new InvalidOperationException("The parameters from and to SHOULD be 20-byte addresses."); } if (!IsPayable(buyer)) { return(false); } if (!Runtime.CheckWitness(buyer)) //0.2 { return(false); } StorageMap saleMul = Storage.CurrentContext.CreateMap(nameof(saleMul)); byte[] smFrom = saleMul.Get(saler); // 如果from名下没有任何售卖单返回错误 if (smFrom == null || smFrom.Length == 0) { MarketBuyErr(buyer, sid, 10013); return(false); } Map <BigInteger, SaleMulInfo> sitems = Helper.Deserialize(smFrom) as Map <BigInteger, SaleMulInfo>; // 如果from名下没有该单号返回错误 if (!sitems.HasKey(sid)) { MarketBuyErr(buyer, sid, 10013); return(false); } SaleMulInfo s = sitems[sid]; // -----------使用nep5购买 if (Nep5transfer("transfer", new object[] { buyer, saler, s.price }) == false) { MarketBuyErr(buyer, sid, 10001); throw new Exception("NEP5transfer Fail!"); } //---------- object[] objs = new object[12]; objs[0] = ExecutionEngine.ExecutingScriptHash; objs[1] = buyer; objs[2] = s.count; for (int i = 0; i < s.count; i++) { objs[i + 3] = s.ids[i]; } // -----------调用EasyNFT 转移资产 if (NFTtransfer("transfer", objs) == false) { throw new Exception("NFTtransfer Fail!"); } sitems.Remove(sid); saleMul.Put(saler, Helper.Serialize(sitems)); NftMarketBuyed(buyer, sid); return(true); }
// 对几个资产进行打包,挂单售卖 private static bool MulSale(object[] args) { if (args.Length < 3) { return(false); } byte[] account = (byte[])args[0]; BigInteger price = (BigInteger)args[1]; BigInteger amount = (BigInteger)args[2]; //Check parameters if (account.Length != 20) { throw new InvalidOperationException("The parameters from and to SHOULD be 20-byte addresses."); } if (amount <= 0 || amount > 9 || price < 0) { throw new InvalidOperationException("The parameter amount MUST be greater than 0."); } if (args.Length < 3 + amount) { return(false); } if (!Runtime.CheckWitness(account)) //0.2 { return(false); } object[] objs = new object[12]; objs[0] = account; objs[1] = ExecutionEngine.ExecutingScriptHash; objs[2] = amount; for (int i = 0; i < amount; i++) { objs[3 + i] = args[3 + i]; } // -----------调用EasyNFT 转移资产 if (NFTtransfer("transfer", objs) == false) { MulSaleErr(account, 10015); throw new Exception("NFTtransfer Fail!"); } //---------- BigInteger sid = _createSaleID(); SaleMulInfo info = new SaleMulInfo(); info.saleid = sid; info.price = price; info.ids = new BigInteger[9]; info.count = amount; for (int i = 0; i < amount; i++) { info.ids[i] = (BigInteger)args[3 + i]; } // 将售卖信息插入售卖表saleMul 中 StorageMap saleMul = Storage.CurrentContext.CreateMap(nameof(saleMul)); byte[] smFrom = saleMul.Get(account); Map <BigInteger, SaleMulInfo> items; if (smFrom == null || smFrom.Length == 0) { items = new Map <BigInteger, SaleMulInfo>(); } else { items = Helper.Deserialize(smFrom) as Map <BigInteger, SaleMulInfo>; } items[sid] = info; saleMul.Put(account, Helper.Serialize(items)); MulSaled(account, info); return(true); }