public override APIResultCodes Authorize <T>(ref T tblock) { if (!(tblock is CancelTradeOrderBlock)) { return(APIResultCodes.InvalidBlockType); } var block = tblock as CancelTradeOrderBlock; // 1. check if the account exists if (!_accountCollection.AccountExists(block.AccountID)) { return(APIResultCodes.AccountDoesNotExist); } TransactionBlock lastBlock = _accountCollection.FindLatestBlock(block.AccountID); if (lastBlock == null) { return(APIResultCodes.CouldNotFindLatestBlock); } var result = VerifyBlock(block, lastBlock); if (result != APIResultCodes.Success) { return(result); } result = VerifyTransactionBlock(block); if (result != APIResultCodes.Success) { return(result); } var original_order = _accountCollection.FindBlockByHash(block.AccountID, block.TradeOrderId) as TradeOrderBlock; if (original_order == null) { return(APIResultCodes.NoTradesFound); } result = ValidateCancellationBalance(block, lastBlock, original_order); if (result != APIResultCodes.Success) { return(result); } Sign(ref block); _accountCollection.AddBlock(block); _TradeMatchEngine.RemoveOrder(original_order); return(base.Authorize(ref tblock)); }
public override APIResultCodes Authorize <T>(ref T tblock) { if (!(tblock is TradeBlock)) { return(APIResultCodes.InvalidBlockType); } var block = tblock as TradeBlock; // 1. check if the account already exists if (!_accountCollection.AccountExists(block.AccountID)) { return(APIResultCodes.AccountDoesNotExist); } TransactionBlock lastBlock = _accountCollection.FindLatestBlock(block.AccountID); if (lastBlock == null) { return(APIResultCodes.CouldNotFindLatestBlock); } var result = VerifyBlock(block, lastBlock); if (result != APIResultCodes.Success) { return(result); } //if (lastBlock.Balances[LyraGlobal.LYRA_TICKER_CODE] <= block.Balances[LyraGlobal.LYRA_TICKER_CODE] + block.Fee) // return AuthorizationResultCodes.NegativeTransactionAmount; // Validate the destination account id if (!Signatures.ValidateAccountId(block.DestinationAccountId)) { return(APIResultCodes.InvalidDestinationAccountId); } result = VerifyTransactionBlock(block); if (result != APIResultCodes.Success) { return(result); } if (!block.ValidateTransaction(lastBlock)) { return(APIResultCodes.SendTransactionValidationFailed); } // TP DO validate the original order var original_order = _accountCollection.FindBlockByHash(block.DestinationAccountId, block.TradeOrderId) as TradeOrderBlock; if (original_order == null) { return(APIResultCodes.TradeOrderValidationFailed); } if (original_order.SellTokenCode != block.BuyTokenCode) { return(APIResultCodes.TradeOrderValidationFailed); } if (original_order.BuyTokenCode != block.SellTokenCode) { return(APIResultCodes.TradeOrderValidationFailed); } // TO DO validate amounts Sign(ref block); _accountCollection.AddBlock(block); // Deactivate the order if it allows only one matching trade if (original_order.MaxQuantity == 1) { _TradeMatchEngine.RemoveOrder(original_order); } return(base.Authorize(ref tblock)); }