-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tx-builder)!: extract entries into separate builder
BREAKING CHANGE: `buildTx`/`unpackTx` works only with transactions If you need to work with node's entry use `packEntry`/`unpackEntry`. BREAKING CHANGE: `Tag` include only transactions Node entries tags moved to `EntryTag`. BREAKING CHANGE: `buildTx` doesn't accept `prefix` anymore Use `decode`/`encode` to convert payload to desired format.
- Loading branch information
Showing
25 changed files
with
667 additions
and
492 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export enum CallReturnType { | ||
Ok = 0, | ||
Error = 1, | ||
Revert = 2, | ||
} | ||
|
||
/** | ||
* @category entry building | ||
*/ | ||
export enum EntryTag { | ||
Account = 10, | ||
Oracle = 20, | ||
// OracleQuery = 21, | ||
Name = 30, | ||
// NameCommitment = 31, | ||
// NameAuction = 37, | ||
Contract = 40, | ||
ContractCall = 41, | ||
ChannelOffChainUpdateTransfer = 570, | ||
ChannelOffChainUpdateDeposit = 571, | ||
ChannelOffChainUpdateWithdraw = 572, | ||
ChannelOffChainUpdateCreateContract = 573, | ||
ChannelOffChainUpdateCallContract = 574, | ||
// ChannelOffChainUpdateMeta = 576, | ||
Channel = 58, | ||
TreesPoi = 60, | ||
// TreesDb = 61, | ||
StateTrees = 62, | ||
Mtree = 63, | ||
MtreeValue = 64, | ||
ContractsMtree = 621, | ||
CallsMtree = 622, | ||
ChannelsMtree = 623, | ||
NameserviceMtree = 624, | ||
OraclesMtree = 625, | ||
AccountsMtree = 626, | ||
// CompilerSophia = 70, | ||
GaMetaTxAuthData = 810, | ||
} |
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,54 @@ | ||
import { Encoded, Encoding } from '../../../utils/encoder'; | ||
import { packRecord, unpackRecord } from '../common'; | ||
import { schemas } from './schema'; | ||
import { EntryTag } from './constants'; | ||
import { EntParams, EntUnpacked } from './schema.generated'; | ||
|
||
const encodingTag = [ | ||
[EntryTag.CallsMtree, Encoding.CallStateTree], | ||
[EntryTag.StateTrees, Encoding.StateTrees], | ||
[EntryTag.TreesPoi, Encoding.Poi], | ||
] as const; | ||
|
||
export function packEntry(params: EntParams & { tag: EntryTag.CallsMtree }): Encoded.CallStateTree; | ||
export function packEntry(params: EntParams & { tag: EntryTag.StateTrees }): Encoded.StateTrees; | ||
export function packEntry(params: EntParams & { tag: EntryTag.TreesPoi }): Encoded.Poi; | ||
/** | ||
* Pack entry | ||
* @category entry builder | ||
* @param params - Params of entry | ||
* @returns Encoded entry | ||
*/ | ||
export function packEntry(params: EntParams): Encoded.Any; | ||
export function packEntry(params: EntParams): Encoded.Any { | ||
const encoding = encodingTag.find(([tag]) => tag === params.tag)?.[1] ?? Encoding.Bytearray; | ||
return packRecord(schemas, EntryTag, params, { packEntry }, encoding); | ||
} | ||
|
||
export function unpackEntry( | ||
encoded: Encoded.CallStateTree, | ||
): EntUnpacked & { tag: EntryTag.CallsMtree }; | ||
export function unpackEntry( | ||
encoded: Encoded.StateTrees, | ||
): EntUnpacked & { tag: EntryTag.StateTrees }; | ||
export function unpackEntry( | ||
encoded: Encoded.Poi, | ||
): EntUnpacked & { tag: EntryTag.TreesPoi }; | ||
/** | ||
* Unpack entry | ||
* @category entry builder | ||
* @param encoded - Encoded entry | ||
* @param expectedTag - Expected entry type | ||
* @returns Params of entry | ||
*/ | ||
export function unpackEntry<T extends EntryTag>( | ||
encoded: Encoded.Any, | ||
expectedTag?: T, | ||
): EntUnpacked & { tag: T }; | ||
export function unpackEntry( | ||
encoded: Encoded.Any, | ||
expectedTag?: EntryTag, | ||
): EntUnpacked { | ||
expectedTag ??= encodingTag.find(([, enc]) => encoded.startsWith(enc))?.[0]; | ||
return unpackRecord(schemas, EntryTag, encoded, expectedTag, { unpackEntry }) as any; | ||
} |
Oops, something went wrong.