async Task <TransactionBlock> DelistOrderAsync(DagSystem sys, SendTransferBlock send) { var daoid = send.Tags["daoid"]; var orderid = send.Tags["orderid"]; var lastblock = await sys.Storage.FindLatestBlockAsync(orderid) as TransactionBlock; var order = (lastblock as IOtcOrder).Order; var sb = await sys.Storage.GetLastServiceBlockAsync(); var sendToTradeBlock = new OtcOrderSendBlock { // block ServiceHash = sb.Hash, // trans Fee = 0, FeeCode = LyraGlobal.OFFICIALTICKERCODE, FeeType = AuthorizationFeeTypes.NoFee, AccountID = lastblock.AccountID, Balances = lastblock.Balances.ToDecimalDict().ToLongDict(), // send DestinationAccountId = (lastblock as IBrokerAccount).OwnerAccountId, // broker Name = ((IBrokerAccount)lastblock).Name, OwnerAccountId = ((IBrokerAccount)lastblock).OwnerAccountId, RelatedTx = send.Hash, // otc Order = new OTCOrder { daoId = ((IOtcOrder)lastblock).Order.daoId, dir = ((IOtcOrder)lastblock).Order.dir, crypto = ((IOtcOrder)lastblock).Order.crypto, fiat = ((IOtcOrder)lastblock).Order.fiat, fiatPrice = ((IOtcOrder)lastblock).Order.fiatPrice, priceType = ((IOtcOrder)lastblock).Order.priceType, price = ((IOtcOrder)lastblock).Order.price, limitMax = ((IOtcOrder)lastblock).Order.limitMax, limitMin = ((IOtcOrder)lastblock).Order.limitMin, payBy = ((IOtcOrder)lastblock).Order.payBy, amount = 0, collateral = ((IOtcOrder)lastblock).Order.collateral, // this is the difference with close. collateralPrice = ((IOtcOrder)lastblock).Order.collateralPrice }, OOStatus = OTCOrderStatus.Delist, }; sendToTradeBlock.Balances[order.crypto] = 0; sendToTradeBlock.AddTag(Block.MANAGEDTAG, ""); // value is always ignored sendToTradeBlock.InitializeBlock(lastblock, NodeService.Dag.PosWallet.PrivateKey, AccountId: NodeService.Dag.PosWallet.AccountId); return(sendToTradeBlock); }
async Task <TransactionBlock> SealOrderAsync(DagSystem sys, SendTransferBlock send) { var daoid = send.Tags["daoid"]; var orderid = send.Tags["orderid"]; var lastblock = await sys.Storage.FindLatestBlockAsync(orderid) as TransactionBlock; var order = (lastblock as IOtcOrder).Order; var sb = await sys.Storage.GetLastServiceBlockAsync(); var sendToTradeBlock = new OtcOrderSendBlock { // block ServiceHash = sb.Hash, // trans Fee = 0, FeeCode = LyraGlobal.OFFICIALTICKERCODE, FeeType = AuthorizationFeeTypes.NoFee, AccountID = lastblock.AccountID, Balances = lastblock.Balances.ToDecimalDict().ToLongDict(), // send DestinationAccountId = (lastblock as IBrokerAccount).OwnerAccountId, // broker Name = ((IBrokerAccount)lastblock).Name, OwnerAccountId = ((IBrokerAccount)lastblock).OwnerAccountId, RelatedTx = send.Hash, // otc Order = new OTCOrder { daoId = ((IOtcOrder)lastblock).Order.daoId, dir = ((IOtcOrder)lastblock).Order.dir, crypto = ((IOtcOrder)lastblock).Order.crypto, fiat = ((IOtcOrder)lastblock).Order.fiat, priceType = ((IOtcOrder)lastblock).Order.priceType, price = ((IOtcOrder)lastblock).Order.price, limitMax = ((IOtcOrder)lastblock).Order.limitMax, limitMin = ((IOtcOrder)lastblock).Order.limitMin, payBy = ((IOtcOrder)lastblock).Order.payBy, fiatPrice = ((IOtcOrder)lastblock).Order.fiatPrice, collateralPrice = ((IOtcOrder)lastblock).Order.collateralPrice, amount = 0, collateral = 0, }, OOStatus = OTCOrderStatus.Closed, }; // when delist, the crypto balance is already zero. // no balance change will vialate the rule of send // so we reduce the balance of LYR, or the collateral, of 0.00000001 if (sendToTradeBlock.Balances[order.crypto] != 0) { sendToTradeBlock.Balances[order.crypto] = 0; } sendToTradeBlock.Balances["LYR"] = 0; // all remaining LYR sendToTradeBlock.AddTag(Block.MANAGEDTAG, ""); // value is always ignored sendToTradeBlock.InitializeBlock(lastblock, NodeService.Dag.PosWallet.PrivateKey, AccountId: NodeService.Dag.PosWallet.AccountId); return(sendToTradeBlock); }