public void get_required_signatures() { var findAccountsArgs = new FindAccountsArgs() { Accounts = new[] { User.Login } }; var accounts = Api.FindAccounts(findAccountsArgs, CancellationToken.None); WriteLine(accounts); Assert.IsFalse(accounts.IsError); var pKey = accounts.Result.Accounts[0].Posting.KeyAuths[0].Key; var args = new GetRequiredSignaturesArgs() { Trx = GetSignedTransaction(), AvailableKeys = new[] { pKey } }; var resp = Api.GetRequiredSignatures(args, CancellationToken.None); WriteLine(resp); Assert.IsFalse(resp.IsError); var obj = Api.CustomGetRequest <JObject>(KnownApiNames.DatabaseApi, "get_required_signatures", args, CancellationToken.None); TestPropetries(resp.Result.GetType(), obj.Result); WriteLine("----------------------------------------------------------------------------"); WriteLine(obj); }
public async Task find_accounts() { var args = new FindAccountsArgs { Accounts = new[] { User.Login } }; var resp = await Api.FindAccountsAsync(args, CancellationToken.None).ConfigureAwait(false); TestPropetries(resp); }
public async Task AccountUpdateTest() { var args = new FindAccountsArgs { Accounts = new[] { User.Login } }; var resp = await Api.FindAccountsAsync(args, CancellationToken.None).ConfigureAwait(false); var acc = resp.Result.Accounts[0]; var op = new AccountUpdateOperation(User.Login, acc.MemoKey, acc.JsonMetadata); await Post(User.ActiveKeys, false, op).ConfigureAwait(false); }
public override async Task <OperationResult <VoidResponse> > UpdateUserProfile(UpdateUserProfileModel model, CancellationToken ct) { return(await Task.Run(() => { if (!TryReconnectChain(ct)) { return new OperationResult <VoidResponse>(new AppError(LocalizationKeys.EnableConnectToBlockchain)); } var keys = ToKeyArr(model.ActiveKey); if (keys == null) { return new OperationResult <VoidResponse>(new AppError(LocalizationKeys.WrongPrivateActimeKey)); } var findAccountsArgs = new FindAccountsArgs { Accounts = new[] { model.Login } }; var resp = _operationManager.FindAccounts(findAccountsArgs, CancellationToken.None); var result = new OperationResult <VoidResponse>(); if (resp.IsError) { OnError(resp, result); return result; } var profile = resp.Result.Accounts.Length == 1 ? resp.Result.Accounts[0] : null; if (profile == null) { result.Error = new BlockchainError(LocalizationKeys.UnexpectedProfileData); return result; } var editedMeta = UpdateProfileJson(profile.JsonMetadata, model); var op = new AccountUpdateOperation(model.Login, profile.MemoKey, editedMeta); var resp2 = _operationManager.BroadcastOperationsSynchronous(keys, ct, op); if (!resp2.IsError) { result.Result = new VoidResponse(); } else { OnError(resp2, result); } return result; }, ct)); }
public void find_accounts() { var args = new FindAccountsArgs() { Accounts = new[] { User.Login } }; var resp = Api.FindAccounts(args, CancellationToken.None); WriteLine(resp); Assert.IsFalse(resp.IsError); var obj = Api.CustomGetRequest <JObject>(KnownApiNames.DatabaseApi, "find_accounts", args, CancellationToken.None); TestPropetries(resp.Result.GetType(), obj.Result); WriteLine("----------------------------------------------------------------------------"); WriteLine(obj); }
public async Task AccountUpdateTest() { var args = new FindAccountsArgs() { Accounts = new[] { User.Login } }; var resp = Api.FindAccounts(args, CancellationToken.None); WriteLine(resp); Assert.IsFalse(resp.IsError); var acc = resp.Result.Accounts[0]; var op = new AccountUpdateOperation(User.Login, acc.MemoKey, acc.JsonMetadata); var response = Post(User.ActiveKeys, false, op); Assert.IsFalse(response.IsError, response.GetErrorMessage()); }
public override async Task <OperationResult <VoidResponse> > UpdateUserProfile(UpdateUserProfileModel model, CancellationToken ct) { var isConnected = await TryReconnectChain(ct); if (!isConnected) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain))); } var keys = ToKeyArr(model.ActiveKey); if (keys == null) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivateActimeKey))); } var args = new FindAccountsArgs { Accounts = new[] { model.Login } }; var resp = await _operationManager.FindAccounts(args, CancellationToken.None); var result = new OperationResult <VoidResponse>(); if (resp.IsError) { result.Exception = new RequestException(resp); return(result); } var profile = resp.Result.Accounts.Length == 1 ? resp.Result.Accounts[0] : null; if (profile == null) { result.Exception = new ValidationException(LocalizationKeys.UnexpectedProfileData); return(result); } var editedMeta = UpdateProfileJson(profile.JsonMetadata, model); var op = new AccountUpdateOperation(model.Login, profile.MemoKey, editedMeta); return(await Broadcast(keys, new BaseOperation[] { op }, ct)); }
public async Task get_required_signatures() { var findAccountsArgs = new FindAccountsArgs { Accounts = new[] { User.Login } }; var accounts = await Api.FindAccounts(findAccountsArgs, CancellationToken.None); if (accounts.IsError) { WriteLine(accounts); } Assert.IsFalse(accounts.IsError); var pKey = accounts.Result.Accounts[0].Posting.KeyAuths[0].Key; var args = new GetRequiredSignaturesArgs { Trx = await GetSignedTransaction(), AvailableKeys = new[] { pKey } }; var resp = await Api.CondenserGetRequiredSignatures(args, CancellationToken.None); TestPropetries(resp); }
/// <summary> /// API name: find_accounts /// Find accounts by primary key (account name) /// /// /// </summary> /// <param name="args">API type: find_accounts_args</param> /// <param name="token">Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.</param> /// <returns>API type: find_accounts_return</returns> /// <exception cref="T:System.OperationCanceledException">The token has had cancellation requested.</exception> public Task <JsonRpcResponse <FindAccountsReturn> > FindAccounts(FindAccountsArgs args, CancellationToken token) { return(CustomGetRequest <FindAccountsReturn>(KnownApiNames.DatabaseApi, "find_accounts", args, token)); }
public override async Task <OperationResult <AccountInfoResponse> > GetAccountInfo(string userName, CancellationToken ct) { var isConnected = await TryReconnectChain(ct); if (!isConnected) { return(new OperationResult <AccountInfoResponse>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain))); } var result = new OperationResult <AccountInfoResponse>(); var args = new FindAccountsArgs { Accounts = new[] { userName } }; var resp = await _operationManager.FindAccounts(args, CancellationToken.None); if (resp.IsError) { result.Exception = new RequestException(resp); return(result); } if (resp.Result.Accounts.Length != 1 || resp.Result.Accounts[0] == null) { return(new OperationResult <AccountInfoResponse>(new ValidationException(LocalizationKeys.UnexpectedProfileData))); } var acc = resp.Result.Accounts[0]; var vestsExchangeRatio = await GetVestsExchangeRatio(ct); if (!vestsExchangeRatio.IsSuccess) { return(new OperationResult <AccountInfoResponse>(vestsExchangeRatio.Exception)); } var effectiveSp = (acc.VestingShares.ToDouble() + acc.ReceivedVestingShares.ToDouble() - acc.DelegatedVestingShares.ToDouble()) * vestsExchangeRatio.Result; result.Result = new AccountInfoResponse { Chains = KnownChains.Steem, PublicPostingKeys = acc.Posting.KeyAuths.Select(i => i.Key.Data).ToArray(), PublicActiveKeys = acc.Active.KeyAuths.Select(i => i.Key.Data).ToArray(), Metadata = JsonConvert.DeserializeObject <AccountMetadata>(acc.JsonMetadata), Balances = new List <BalanceModel> { new BalanceModel(acc.Balance.ToDouble(), 3, CurrencyType.Steem) { EffectiveSp = effectiveSp, RewardSteem = acc.RewardSteemBalance.ToDouble(), RewardSp = acc.RewardVestingBalance.ToDouble() * vestsExchangeRatio.Result, RewardSbd = acc.RewardSbdBalance.ToDouble(), DelegatedToMe = acc.ReceivedVestingShares.ToDouble() * vestsExchangeRatio.Result, DelegatedByMe = acc.DelegatedVestingShares.ToDouble() * vestsExchangeRatio.Result, ToWithdraw = long.Parse(acc.ToWithdraw.ToString()) / 10e5 * vestsExchangeRatio.Result }, new BalanceModel(acc.SbdBalance.ToDouble(), 3, CurrencyType.Sbd) { EffectiveSp = effectiveSp, RewardSteem = acc.RewardSteemBalance.ToDouble(), RewardSp = acc.RewardVestingBalance.ToDouble() * vestsExchangeRatio.Result, RewardSbd = acc.RewardSbdBalance.ToDouble(), DelegatedToMe = acc.ReceivedVestingShares.ToDouble() * vestsExchangeRatio.Result, DelegatedByMe = acc.DelegatedVestingShares.ToDouble() * vestsExchangeRatio.Result, ToWithdraw = long.Parse(acc.ToWithdraw.ToString()) / 10e5 * vestsExchangeRatio.Result } } }; return(result); }
public override async Task <OperationResult <VoidResponse> > ValidatePrivateKey(ValidatePrivateKeyModel model, CancellationToken ct) { var keys = ToKey(model.PrivateKey); if (keys == null) { switch (model.KeyRoleType) { case KeyRoleType.Active: return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivateActimeKey))); case KeyRoleType.Posting: return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivatePostingKey))); } } var isConnected = await TryReconnectChain(ct); if (!isConnected) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain))); } var result = new OperationResult <VoidResponse>(); var args = new FindAccountsArgs { Accounts = new[] { model.Login } }; var resp = await _operationManager.FindAccounts(args, CancellationToken.None); if (resp.IsError) { result.Exception = new RequestException(resp); return(result); } if (resp.Result.Accounts.Length != 1 || resp.Result.Accounts[0] == null) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.UnexpectedProfileData))); } Authority authority; switch (model.KeyRoleType) { case KeyRoleType.Active: authority = resp.Result.Accounts[0].Active; break; case KeyRoleType.Posting: authority = resp.Result.Accounts[0].Posting; break; default: throw new NotImplementedException(); } var isSame = KeyHelper.ValidatePrivateKey(keys, authority.KeyAuths.Select(i => i.Key.Data).ToArray()); if (isSame) { return(new OperationResult <VoidResponse>(new VoidResponse())); } switch (model.KeyRoleType) { case KeyRoleType.Active: return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivateActimeKey))); default: return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivatePostingKey))); } }