public void DeleteIndex(TransactionTransfer record) { database.DeleteBalanceIndex(record.FromAddress, record.TokenSymbol); database.DeleteBalanceIndex(record.ToAddress, record.TokenSymbol); IndexBalanceCache.Remove(record.FromAddress, record.TokenSymbol); IndexBalanceCache.Remove(record.ToAddress, record.TokenSymbol); }
public string AddTransfer( long nonce, decimal fee, string tokenSymbol, string fromAddress, string toAddress, decimal amount) { var token = indexServices.TokenIndex.Get(tokenSymbol); if (token == null) { throw new ValidationException(ResponseCodes.TokenNotRecognized, ResponseMessages.TokenNotRecognized); } //Get the non-decimal amount var factoredAmount = ToFactoredPrice(amount, token.Decimals); TransactionTransfer transfer = new TransactionTransfer(); transfer.Nonce = nonce; transfer.Fee = ToFactoredPriceFee(fee); transfer.TokenSymbol = tokenSymbol; transfer.FromAddress = fromAddress; transfer.ToAddress = toAddress; transfer.Amount = factoredAmount; transfer.TransactionId = GenerateTransactionId(transfer); //Check if same transaction has already been received if (IsTransactionInPending(transfer.TransactionId)) { return(transfer.TransactionId); } //Verify fee account balance if (!HasSufficientBalanceFee(fromAddress, fee)) { throw new ValidationException(ResponseCodes.InsufficientFundsForFee, ResponseMessages.InsufficientFundsForFee); } //Verify account balance if (!HasSufficientBalance(fromAddress, tokenSymbol, amount)) { throw new ValidationException(ResponseCodes.InsufficientFunds, ResponseMessages.InsufficientFunds); } ApplicationState.PendingRecordsAdd(transfer); return(transfer.TransactionId); }
public void AddToIndex(TransactionTransfer record) { if (record == null) { return; } UpdateBalanceIndex(record.FromAddress, record.ToAddress, record.TokenSymbol, record.Amount); //Update fee holding balance if (record.Fee > 0) { UpdateBalanceIndex(record.FromAddress, ReservedAddresses.FeeWallet, nativeToken, record.Fee); } }
public void CreateGenesisBlock( string ownerAddress, string nativeTokenName, string nativeTokenSymbol, long initialSupply, short decimals) { if (LastBlock != null || (ApplicationState.PendingRecords != null && ApplicationState.PendingRecords.Count > 0)) { throw new Exception("Error CreateGenesisBlock: Chain already exist."); } List <Transaction> transactions = new List <Transaction>(); //Deploy native token to genesis block TransactionToken nativeToken = new TransactionToken(); nativeToken.Name = nativeTokenName; nativeToken.Symbol = nativeTokenSymbol; nativeToken.Decimals = decimals; nativeToken.TransactionId = GenerateTransactionId(nativeToken); transactions.Add(nativeToken); //Transfer native token supply to owner address TransactionTransfer transfer = new TransactionTransfer(); transfer.TokenSymbol = nativeTokenSymbol; transfer.FromAddress = null; transfer.ToAddress = ownerAddress; transfer.Amount = ToFactoredPrice(initialSupply, decimals); transfer.TransactionId = GenerateTransactionId(transfer); transactions.Add(transfer); ApplicationState.PendingRecordsAddRange(transactions); //Create genesis block var header = CreateBlockHeader(true); var block = CreateBlockAndClearPendingTx(header); //Push genesis block to blockchain database.SaveBlock(block); //Update index IndexServices indexServices = new IndexServices(); indexServices.UpdateIndex(block); }
public string AddToken( long nonce, decimal fee, string symbol, string name, long totalSupply, short decimals, string owner) { TransactionToken token = new TransactionToken(); token.Nonce = nonce; token.Fee = ToFactoredPriceFee(fee); token.Symbol = symbol; token.Name = name; token.Decimals = decimals; token.TransactionId = GenerateTransactionId(token); //Check if same transaction has already been received if (IsTransactionInPending(token.TransactionId)) { return(token.TransactionId); } ////Verify if sender if owner of block and have permission to create tokens //var chainOriginator = indexServices.OwnerIndex.Get(); //if(chainOriginator.Address != sender) //{ // throw new ValidationException(ResponseCodes.InsufficientPermission, ResponseMessages.InsufficientPermission); //} //Verify fee account balance if (!HasSufficientBalanceFee(owner, fee)) { throw new ValidationException(ResponseCodes.InsufficientFundsForFee, ResponseMessages.InsufficientFundsForFee); } //Check if token already exist if (indexServices.TokenIndex.Get(symbol) != null) { throw new ValidationException(ResponseCodes.TokenAlreadyExists, ResponseMessages.TokenAlreadyExists); } TransactionTransfer transfer = new TransactionTransfer(); transfer.Nonce = nonce; transfer.TokenSymbol = symbol; transfer.FromAddress = null; transfer.ToAddress = owner; transfer.Amount = ToFactoredPrice(totalSupply, decimals); transfer.TransactionId = GenerateTransactionId(transfer); //Check if same transaction has already been received if (IsTransactionInPending(transfer.TransactionId)) { return(token.TransactionId); } ApplicationState.PendingRecordsAdd(token); ApplicationState.PendingRecordsAdd(transfer); return(token.TransactionId); }
public void Save(TransactionTransfer transactionTransfer) { Save(transactionTransfer.CaptureTransfer); Save(transactionTransfer.ChargeTransfer); }