/// <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)); }
/// <summary> /// Builds and configures Centaurus vault /// </summary> /// <returns>Transaction cursor</returns> private async Task <long> BuildAndConfigureVault(AccountModel vaultAccount) { var majority = MajorityHelper.GetMajorityCount(constellationInitInfo.Auditors.Count()); var sourceAccount = await Context.StellarDataProvider.GetAccountData(vaultAccount.KeyPair.AccountId); var transactionBuilder = new TransactionBuilder(sourceAccount.ToITransactionBuilderAccount()); transactionBuilder.SetFee(10_000); foreach (var a in constellationInitInfo.Assets) { if (a.IsXlm) { throw new InvalidOperationException("Native assets are supported by default."); //better to throw exception to avoid confusions with id } if (vaultAccount.ExistingTrustLines.Any(ta => ta == a.ToString())) { continue; } var trustOperation = new ChangeTrustOperation.Builder(a.ToAsset(), "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(Context.Settings.KeyPair); var result = await Context.StellarDataProvider.SubmitTransaction(transaction); if (!result.IsSuccess) { throw new Exception($"Transaction failed. Result Xdr: {result.ResultXdr}"); } var tx = await Context.StellarDataProvider.GetTransaction(result.Hash); return(tx.PagingToken); }