-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRA-109] Add parent subaccount websocket (#1463)
- Loading branch information
1 parent
cffdb5f
commit 355d9e9
Showing
17 changed files
with
451 additions
and
120 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
indexer/packages/postgres/__tests__/lib/parent-subaccount-helpers.ts
This file contains 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,15 @@ | ||
import { | ||
getParentSubaccountNum, | ||
} from '../../src/lib/parent-subaccount-helpers'; | ||
|
||
describe('getParentSubaccountNum', () => { | ||
it('Gets the parent subaccount number from a child subaccount number', () => { | ||
expect(getParentSubaccountNum(0)).toEqual(0); | ||
expect(getParentSubaccountNum(128)).toEqual(0); | ||
expect(getParentSubaccountNum(128 * 999 - 1)).toEqual(127); | ||
}); | ||
|
||
it('Throws an error if the child subaccount number is greater than the max child subaccount number', () => { | ||
expect(() => getParentSubaccountNum(128001)).toThrowError('Child subaccount number must be less than or equal to 128000'); | ||
}); | ||
}); |
This file contains 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
11 changes: 11 additions & 0 deletions
11
indexer/packages/postgres/src/lib/parent-subaccount-helpers.ts
This file contains 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,11 @@ | ||
import { | ||
CHILD_SUBACCOUNT_MULTIPLIER, | ||
MAX_PARENT_SUBACCOUNTS, | ||
} from '../constants'; | ||
|
||
export function getParentSubaccountNum(childSubaccountNum: number): number { | ||
if (childSubaccountNum > MAX_PARENT_SUBACCOUNTS * CHILD_SUBACCOUNT_MULTIPLIER) { | ||
throw new Error(`Child subaccount number must be less than or equal to ${MAX_PARENT_SUBACCOUNTS * CHILD_SUBACCOUNT_MULTIPLIER}`); | ||
} | ||
return childSubaccountNum % MAX_PARENT_SUBACCOUNTS; | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.