Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new makeStakeTransaction API #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/core/currency/wallet/currency-wallet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,6 +20,7 @@ import {
type EdgePaymentProtocolInfo,
type EdgeReceiveAddress,
type EdgeSpendInfo,
type EdgeStakingSettings,
type EdgeTokenInfo,
type EdgeTransaction,
type EdgeWalletInfo
Expand Down Expand Up @@ -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<EdgeTransaction> {
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Need to add a callback to the engine to tell us it changed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

return tx
},

async parseUri(uri: string, currencyCode?: string): Promise<EdgeParsedUri> {
const tools = await getCurrencyTools(ai, walletInfo.type)
return tools.parseUri(
Expand Down
26 changes: 25 additions & 1 deletion src/types/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export type EdgeCurrencyInfo = {
pluginName: string,
denominations: Array<EdgeDenomination>,
requiredConfirmations?: number,
supportsStaking?: boolean,
walletType: string,

// Configuration options:
Expand Down Expand Up @@ -223,6 +224,13 @@ export type EdgeSpendInfo = {
otherParams?: Object
}

export type EdgeStakingSettings =
| { stakingEnabled: false }
| {
stakingEnabled: true,
delegateAddress: string
}

// query data ----------------------------------------------------------

export type EdgeDataDump = {
Expand Down Expand Up @@ -359,6 +367,12 @@ export type EdgeCurrencyEngine = {
paymentProtocolUrl: string
) => Promise<EdgePaymentProtocolInfo>,

// Staking:
+stakingSettings?: EdgeStakingSettings,
changeStakingSettings?: (
stakingSettings: EdgeStakingSettings
) => Promise<EdgeTransaction>,

// Escape hatch:
+otherMethods?: Object
}
Expand Down Expand Up @@ -478,16 +492,20 @@ export type EdgeCurrencyWallet = {
getEnabledTokens(): Promise<Array<string>>,
addCustomToken(token: EdgeTokenInfo): Promise<mixed>,

// Transactions:
// Transaction history:
getNumTransactions(opts?: EdgeCurrencyCodeOptions): Promise<number>,
getTransactions(
opts?: EdgeGetTransactionsOptions
): Promise<Array<EdgeTransaction>>,

// Addresses:
getReceiveAddress(
opts?: EdgeCurrencyCodeOptions
): Promise<EdgeReceiveAddress>,
saveReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
lockReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,

// Sending:
makeSpend(spendInfo: EdgeSpendInfo): Promise<EdgeTransaction>,
signTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
broadcastTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
Expand All @@ -503,6 +521,12 @@ export type EdgeCurrencyWallet = {
paymentProtocolUrl: string
): Promise<EdgePaymentProtocolInfo>,

// Staking:
+stakingSettings: EdgeStakingSettings,
changeStakingSettings: (
stakingSettings: EdgeStakingSettings
) => Promise<EdgeTransaction>,

// Wallet management:
resyncBlockchain(): Promise<mixed>,
dumpData(): Promise<EdgeDataDump>,
Expand Down