-
Notifications
You must be signed in to change notification settings - Fork 61
Add core-side synthetic destination for swap-to-address #730
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
Draft
j0ntz
wants to merge
3
commits into
master
Choose a base branch
from
jon/stealth-send-swap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { bridgifyObject } from 'yaob' | ||
|
|
||
| import { | ||
| EdgeAddress, | ||
| EdgeCurrencyConfig, | ||
| EdgeCurrencyWallet, | ||
| EdgeMemo, | ||
| EdgeReceiveAddress | ||
| } from '../../types/types' | ||
|
|
||
| /** | ||
| * A prefix marking a synthetic destination wallet's `id`. A swap-to-address | ||
| * destination has no real payout wallet, so this id does not resolve to one; | ||
| * it only exists because plugins read `toWallet.id` for order metadata. | ||
| */ | ||
| export const SYNTHETIC_WALLET_ID_PREFIX = 'synthetic://' | ||
|
|
||
| /** | ||
| * Build a synthetic, bridgified destination wallet for a swap-to-address | ||
| * request. It is backed by the real `currencyConfig` core already holds, so | ||
| * `currencyInfo` and `currencyConfig.allTokens` are authentic, while | ||
| * `getAddresses` / `getReceiveAddress` return the pasted destination address. | ||
| * | ||
| * It is bridgified here (core-side) so swap-plugin method calls work unchanged | ||
| * and so it survives the yaob wire format when it rides back to the GUI inside | ||
| * `quote.request.toWallet`. A GUI-built fake cannot do this: its function | ||
| * properties fail to cross the bridge (see the Phase 1 verdict). | ||
| */ | ||
| export function makeSyntheticDestinationWallet( | ||
| currencyConfig: EdgeCurrencyConfig, | ||
| toAddress: string, | ||
| toMemos: EdgeMemo[] = [] | ||
| ): EdgeCurrencyWallet { | ||
| const { currencyInfo } = currencyConfig | ||
|
|
||
| const addresses: EdgeAddress[] = [ | ||
| { addressType: 'publicAddress', publicAddress: toAddress } | ||
| ] | ||
| const receiveAddress: EdgeReceiveAddress = { | ||
| publicAddress: toAddress, | ||
| metadata: {}, | ||
| nativeAmount: '0' | ||
| } | ||
|
|
||
| const wallet = { | ||
| id: `${SYNTHETIC_WALLET_ID_PREFIX}${currencyInfo.pluginId}`, | ||
| type: currencyInfo.walletType, | ||
| currencyConfig, | ||
| currencyInfo, | ||
|
|
||
| async getAddresses(): Promise<EdgeAddress[]> { | ||
| return addresses | ||
| }, | ||
|
|
||
| /** | ||
| * Destination memos (e.g. an XRP destination tag) for the payout. | ||
| * Not part of `EdgeCurrencyWallet`; see `EdgeSyntheticDestinationWallet`. | ||
| * Plugins that support destination memos detect this method at runtime. | ||
| */ | ||
| async getMemos(): Promise<EdgeMemo[]> { | ||
| return toMemos | ||
| }, | ||
|
|
||
| async getReceiveAddress(): Promise<EdgeReceiveAddress> { | ||
| return receiveAddress | ||
| } | ||
| } | ||
| bridgifyObject(wallet) | ||
|
|
||
| // The synthetic destination only implements the `EdgeCurrencyWallet` surface | ||
| // that swap plugins read on `toWallet` (id, type, currencyInfo, | ||
| // currencyConfig, getAddresses, getReceiveAddress), plus the synthetic-only | ||
| // `getMemos` (see `EdgeSyntheticDestinationWallet`). It is never used as a | ||
| // source wallet, so the spend/sign/sync methods are intentionally absent. | ||
| return wallet as unknown as EdgeCurrencyWallet | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.