From 0f758eae1cd7807d5f2b3afb477a4faabb5a0f39 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Tue, 30 Jul 2019 10:37:19 -0700 Subject: [PATCH] Add an `EdgeStakingSettings` configuration --- .../currency/wallet/currency-wallet-api.js | 20 +++++++++++++- src/types/types.js | 26 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/core/currency/wallet/currency-wallet-api.js b/src/core/currency/wallet/currency-wallet-api.js index 9ab83f75d..fdfe271ae 100644 --- a/src/core/currency/wallet/currency-wallet-api.js +++ b/src/core/currency/wallet/currency-wallet-api.js @@ -2,7 +2,7 @@ import { add, div, lte, mul, sub } from 'biggystring' import { type Disklet } from 'disklet' -import { bridgifyObject, onMethod, watchMethod } from 'yaob' +import { bridgifyObject, onMethod, update, watchMethod } from 'yaob' import { CurrencyWalletSync } from '../../../client-side.js' import { @@ -20,6 +20,7 @@ import { type EdgePaymentProtocolInfo, type EdgeReceiveAddress, type EdgeSpendInfo, + type EdgeStakingSettings, type EdgeTokenInfo, type EdgeTransaction, type EdgeWalletInfo @@ -459,6 +460,23 @@ export function makeCurrencyWalletApi( return getMax('0', add(balance, '1')) }, + get stakingSettings(): EdgeStakingSettings { + return engine.stakingSettings != null + ? engine.stakingSettings + : { stakingEnabled: false } + }, + + async changeStakingSettings( + stakingSettings: EdgeStakingSettings + ): Promise { + if (engine.changeStakingSettings == null) { + throw new Error('This currency does not support staking') + } + const tx = await engine.changeStakingSettings(stakingSettings) + update(out) // Check for changes to this.stakingSettings + return tx + }, + async parseUri(uri: string, currencyCode?: string): Promise { const tools = await getCurrencyTools(ai, walletInfo.type) return tools.parseUri( diff --git a/src/types/types.js b/src/types/types.js index bfc0731db..f4de1f226 100644 --- a/src/types/types.js +++ b/src/types/types.js @@ -137,6 +137,7 @@ export type EdgeCurrencyInfo = { pluginName: string, denominations: Array, requiredConfirmations?: number, + supportsStaking?: boolean, walletType: string, // Configuration options: @@ -223,6 +224,13 @@ export type EdgeSpendInfo = { otherParams?: Object } +export type EdgeStakingSettings = + | { stakingEnabled: false } + | { + stakingEnabled: true, + delegateAddress: string + } + // query data ---------------------------------------------------------- export type EdgeDataDump = { @@ -359,6 +367,12 @@ export type EdgeCurrencyEngine = { paymentProtocolUrl: string ) => Promise, + // Staking: + +stakingSettings?: EdgeStakingSettings, + changeStakingSettings?: ( + stakingSettings: EdgeStakingSettings + ) => Promise, + // Escape hatch: +otherMethods?: Object } @@ -478,16 +492,20 @@ export type EdgeCurrencyWallet = { getEnabledTokens(): Promise>, addCustomToken(token: EdgeTokenInfo): Promise, - // Transactions: + // Transaction history: getNumTransactions(opts?: EdgeCurrencyCodeOptions): Promise, getTransactions( opts?: EdgeGetTransactionsOptions ): Promise>, + + // Addresses: getReceiveAddress( opts?: EdgeCurrencyCodeOptions ): Promise, saveReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise, lockReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise, + + // Sending: makeSpend(spendInfo: EdgeSpendInfo): Promise, signTx(tx: EdgeTransaction): Promise, broadcastTx(tx: EdgeTransaction): Promise, @@ -503,6 +521,12 @@ export type EdgeCurrencyWallet = { paymentProtocolUrl: string ): Promise, + // Staking: + +stakingSettings: EdgeStakingSettings, + changeStakingSettings: ( + stakingSettings: EdgeStakingSettings + ) => Promise, + // Wallet management: resyncBlockchain(): Promise, dumpData(): Promise,