/// <summary> /// Builds and configures Centaurus vault /// </summary> /// <returns>Transaction cursor</returns> private async Task <long> BuildAndConfigureVault(stellar_dotnet_sdk.responses.AccountResponse vaultAccount) { var majority = MajorityHelper.GetMajorityCount(constellationInitInfo.Auditors.Count()); var sourceAccount = await StellarAccountHelper.GetStellarAccount(vaultAccount.KeyPair); var transactionBuilder = new TransactionBuilder(sourceAccount); transactionBuilder.SetFee(10_000); var existingTrustlines = vaultAccount.Balances .Where(b => b.Asset is stellar_dotnet_sdk.AssetTypeCreditAlphaNum) .Select(b => b.Asset) .Cast <stellar_dotnet_sdk.AssetTypeCreditAlphaNum>(); foreach (var a in constellationInitInfo.Assets) { var asset = a.ToAsset() as stellar_dotnet_sdk.AssetTypeCreditAlphaNum; if (asset == null) //if null than asset is stellar_dotnet_sdk.AssetTypeNative { throw new InvalidOperationException("Native assets are supported by default."); //better to throw exception to avoid confusions with id } if (existingTrustlines.Any(t => t.Code == asset.Code && t.Issuer == asset.Issuer)) { continue; } var trustOperation = new ChangeTrustOperation.Builder(asset, "922337203685.4775807"); transactionBuilder.AddOperation(trustOperation.Build()); } var optionOperationBuilder = new SetOptionsOperation.Builder() .SetMasterKeyWeight(0) .SetLowThreshold(majority) .SetMediumThreshold(majority) .SetHighThreshold(majority); transactionBuilder.AddOperation(optionOperationBuilder.Build()); foreach (var signer in constellationInitInfo.Auditors) { transactionBuilder.AddOperation(new SetOptionsOperation.Builder().SetSigner(Signer.Ed25519PublicKey(signer), 1).Build()); } var transaction = transactionBuilder.Build(); transaction.Sign(Global.Settings.KeyPair); var result = await Global.StellarNetwork.Server.SubmitTransaction(transaction); if (!result.IsSuccess()) { throw new Exception($"Transaction failed. Result Xdr: {result.ResultXdr}"); } var tx = await Global.StellarNetwork.Server.Transactions.Transaction(result.Hash); return(long.Parse(tx.PagingToken)); }
private async void CreateBalances() { //Change this, this should be used with the server the wallet is using and with the account you selected, //not a hard coded one. Server server = new Server("https://horizon-testnet.stellar.org/"); KeyPair accountKeyPair = KeyPair.FromAccountId("GDLIITOORUA7DN3DDFEGNCGNFVRFKJKFOXJOE2FO4FYMFQF5LRT5YL7U"); stellar_dotnet_sdk.responses.AccountResponse accountResponse = await server.Accounts.Account(accountKeyPair); for (int i = 0; i < accountResponse.Balances.Length; i++) { stellar_dotnet_sdk.responses.Balance balance = accountResponse.Balances[i]; AssetCard assetCard = new AssetCard(); //Set AssetCard Balance Balance assetCardBalance = new Balance(); assetCard.Balance = assetCardBalance; assetCardBalance.Amount = balance.BalanceString; //Check if it's native or not if (balance.AssetType == "native") { assetCardBalance.AssetCode = "XLM"; assetCardBalance.IssuerAddress = "Native Lumens"; } else { assetCardBalance.AssetCode = balance.AssetCode; assetCardBalance.IssuerAddress = balance.AssetIssuer.AccountId; } //Set AssetCard Other assetCard.BgColor = "#275AF0"; //Add it to the list _assetsCards.Add(assetCard); } }