-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: #1989: subaccount filter in ownedPositionIds
#2006
Changes from 7 commits
2350c09
b045f75
3b44f94
8d6b007
fd51582
6e6e1c4
28e0399
a06bff8
b42279c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@penumbra-zone/storage': major | ||
'@penumbra-zone/protobuf': minor | ||
'@penumbra-zone/services': minor | ||
'@penumbra-zone/types': minor | ||
'@penumbra-zone/wasm': minor | ||
--- | ||
|
||
- storage: add subaccount filter to `getOwnedPositionIds` method | ||
- protobuf: sync latest changes in penumbra protobufs | ||
- services: add subaccount filter to `ownedPositionIds` method in ViewService | ||
- types: change `isControlledAddress` wasm method to `getIndexByAddress` | ||
- wasm: change `isControlledAddress` method to `getIndexByAddress` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,9 +97,14 @@ export interface IndexedDbInterface { | |
getOwnedPositionIds( | ||
positionState: PositionState | undefined, | ||
tradingPair: TradingPair | undefined, | ||
subaccount: AddressIndex | undefined, | ||
): AsyncGenerator<PositionId, void>; | ||
addPosition(positionId: PositionId, position: Position): Promise<void>; | ||
updatePosition(positionId: PositionId, newState: PositionState): Promise<void>; | ||
addPosition(positionId: PositionId, position: Position, subaccount?: AddressIndex): Promise<void>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
updatePosition( | ||
positionId: PositionId, | ||
newState: PositionState, | ||
subaccount?: AddressIndex, | ||
): Promise<void>; | ||
addEpoch(startHeight: bigint): Promise<void>; | ||
getEpochByHeight(height: bigint): Promise<Epoch | undefined>; | ||
upsertValidatorInfo(validatorInfo: ValidatorInfo): Promise<void>; | ||
|
@@ -297,6 +302,7 @@ export interface PenumbraDb extends DBSchema { | |
export interface PositionRecord { | ||
id: Jsonified<PositionId>; // PositionId (must be JsonValue because ['id']['inner'] is a key ) | ||
position: Jsonified<Position>; // Position | ||
subaccount?: Jsonified<AddressIndex>; // Position AddressIndex | ||
} | ||
|
||
export type Tables = Record<string, StoreNames<PenumbraDb>>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ use std::collections::BTreeMap; | |
|
||
use indexed_db_futures::IdbDatabase; | ||
use penumbra_compact_block::{CompactBlock, StatePayload}; | ||
use penumbra_keys::keys::AddressIndex; | ||
use penumbra_keys::{Address, FullViewingKey}; | ||
use penumbra_proto::DomainType; | ||
use penumbra_sct::Nullifier; | ||
|
@@ -16,7 +17,7 @@ use wasm_bindgen::prelude::wasm_bindgen; | |
use wasm_bindgen::JsValue; | ||
|
||
use crate::error::WasmResult; | ||
use crate::keys::is_controlled_inner; | ||
use crate::keys::controlled_by_index; | ||
use crate::note_record::SpendableNoteRecord; | ||
use crate::storage::{init_idb_storage, Storage}; | ||
use crate::swap_record::SwapRecord; | ||
|
@@ -307,13 +308,17 @@ impl ViewServer { | |
Ok(root.encode_to_vec()) | ||
} | ||
|
||
/// Checks if address is controlled by view server full viewing key | ||
/// Get the address index by provided address | ||
/// Returns: `Uint8Array representing inner Address` | ||
#[wasm_bindgen] | ||
pub fn is_controlled_address(&self, address: &[u8]) -> WasmResult<bool> { | ||
pub fn get_index_by_address(full_viewing_key: &[u8], address: &[u8]) -> WasmResult<JsValue> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: what's the functional difference between this and the other get_index_by_address method in the keys dir – are these not duplicates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inspecting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's right. The block processor uses view server implementation from wasm, so i tried to stick to it without importing methods from other parts of the code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. block processor calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. basically hinting at that we should remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, this change wasn't really needed. Removed all WASM code updates in favor of the old version |
||
utils::set_panic_hook(); | ||
|
||
let address: Address = Address::decode(address)?; | ||
Ok(is_controlled_inner(&self.fvk, &address)) | ||
let fvk: FullViewingKey = FullViewingKey::decode(full_viewing_key)?; | ||
let index: Option<AddressIndex> = controlled_by_index(&fvk, &address).map(Into::into); | ||
let result = serde_wasm_bindgen::to_value(&index)?; | ||
Ok(result) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: could we consider adding a few additional tests?
getOwnedPositionIds
with no positions in the database and check it returns an empty array,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added 1 and 2, number 3 is sufficiently covered by 'should get all position with given subaccount index' test