public override bool Execute(TransactionResultCapsule result) { long fee = CalcFee(); try { ExchangeTransactionContract exchage_tx_contract = this.contract.Unpack <ExchangeTransactionContract>(); AccountCapsule account = this.db_manager.Account.Get(exchage_tx_contract.OwnerAddress.ToByteArray()); ExchangeCapsule exchange = this.db_manager.ExchangeFinal.Get(BitConverter.GetBytes(exchage_tx_contract.ExchangeId)); byte[] first_token_id = exchange.FirstTokenId.ToByteArray(); byte[] second_token_id = exchange.SecondTokenId.ToByteArray(); byte[] token_id = exchage_tx_contract.TokenId.ToByteArray(); long token_quantity = exchage_tx_contract.Quant; byte[] other_token_id = null; long other_token_quantity = exchange.Transaction(token_id, token_quantity); other_token_id = token_id.SequenceEqual(first_token_id) ? second_token_id : first_token_id; long new_balance = account.Balance - CalcFee(); account.Balance = new_balance; if (token_id.SequenceEqual(COMPARE_CHARICTOR)) { account.Balance = new_balance - token_quantity; } else { account.ReduceAssetAmountV2(token_id, token_quantity, this.db_manager); } if (other_token_id.SequenceEqual(COMPARE_CHARICTOR)) { account.Balance = new_balance + other_token_quantity; } else { account.AddAssetAmountV2(other_token_id, other_token_quantity, this.db_manager); } this.db_manager.Account.Put(account.CreateDatabaseKey(), account); this.db_manager.PutExchangeCapsule(exchange); result.ExchangeReceivedAmount = other_token_quantity; result.SetStatus(fee, code.Sucess); } catch (ItemNotFoundException e) { Logger.Debug(e.Message); result.SetStatus(fee, code.Failed); throw new ContractExeException(e.Message); } catch (InvalidProtocolBufferException e) { Logger.Debug(e.Message); result.SetStatus(fee, code.Failed); throw new ContractExeException(e.Message); } return(true); }