private async Task <(string, decimal)> ProcessAccountMergeAsync(HorizonAccountOperation operation, string address) { var tx = await _client.GetTransactionAsync(operation.TransactionHash); var xdr = Convert.FromBase64String(tx.ResultMetaXdr); var reader = new XdrDataInputStream(xdr); var txMeta = TransactionMeta.Decode(reader); var mergeMeta = txMeta.Operations.First ( op => op.Changes.InnerValue.Any ( c => c.Discriminant.InnerValue == LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_REMOVED && KeyPair.FromXdrPublicKey(c.Removed.Account.AccountID.InnerValue).Address == operation.SourceAccount ) ); var sourceAccountStateMeta = mergeMeta.Changes.InnerValue .First ( c => c.Discriminant.InnerValue == LedgerEntryChangeType.LedgerEntryChangeTypeEnum.LEDGER_ENTRY_STATE && KeyPair.FromXdrPublicKey(c.State.Data.Account.AccountID.InnerValue).Address == operation.SourceAccount ); var amount = sourceAccountStateMeta.State.Data.Account.Balance.InnerValue * _nativeAssetMultiplier; if (address.Equals(operation.Into, StringComparison.InvariantCultureIgnoreCase)) { return(_nativeAssetCode, amount); } return(_nativeAssetCode, -amount); }
private (string, decimal) ProcessPayment(HorizonAccountOperation operation, string address) { var amount = decimal.Parse(operation.Amount, CultureInfo.InvariantCulture); if (address.Equals(operation.To, StringComparison.InvariantCultureIgnoreCase)) { return(GetAsset(operation), amount); } return(GetAsset(operation), -amount); }
private (string, decimal) ProcessCreateAccount(HorizonAccountOperation operation, string address) { var amount = decimal.Parse(operation.StartingBalance, CultureInfo.InvariantCulture); if (address.Equals(operation.Account, StringComparison.InvariantCultureIgnoreCase)) { return(_nativeAssetCode, amount); } return(_nativeAssetCode, -amount); }
private string GetAsset(HorizonAccountOperation operation) { var asset = operation.AssetType == "native" ? _nativeAssetCode : operation.AssetCode; if (string.IsNullOrWhiteSpace(asset)) { throw new InvalidOperationException($"Unknown asset code. Asset type is: {operation.AssetType}"); } return(asset); }
private (string Asset, decimal Value) ProcessChangeTrust(HorizonAccountOperation operation, string address) { return(GetAsset(operation), 0M); }