-
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.
feat(tx-builder)!: deserialisation of
channels.get.offchain_state
BREAKING CHANGE: StateTrees fields decoded as objects mapping key to decoded entry instead internals BREAKING CHANGE: The content of Tag.*Mtree entries decoded and moved to `payload` field
- Loading branch information
Showing
8 changed files
with
295 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Tag } from '../constants'; | ||
import { | ||
encode, Encoding, Encoded, decode, | ||
} from '../../../utils/encoder'; | ||
import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index'; | ||
|
||
export default function genMapField<E extends Encoding, T extends Tag>(encoding: E, tag: T): { | ||
serialize: ( | ||
// TODO: replace with `TxParams & { tag: T }`, | ||
// but fix TS2502 value is referenced directly or indirectly in its own type annotation | ||
value: Record<Encoded.Generic<E>, any>, options: { buildTx: typeof buildTxType } | ||
) => Buffer; | ||
deserialize: ( | ||
value: Buffer, options: { unpackTx: typeof unpackTxType }, | ||
// TODO: replace with `TxUnpacked & { tag: T }`, | ||
// TS2577 Return type annotation circularly references itself | ||
) => Record<Encoded.Generic<E>, any>; | ||
recursiveType: true; | ||
} { | ||
return { | ||
serialize(object, { buildTx }) { | ||
return decode(buildTx({ | ||
tag: Tag.Mtree, | ||
values: Object.entries(object).map(([key, value]) => ({ | ||
tag: Tag.MtreeValue, | ||
key: decode(key as Encoded.Generic<E>), | ||
value: decode(buildTx({ ...value as any, tag })), | ||
})), | ||
})); | ||
}, | ||
|
||
deserialize(buffer, { unpackTx }) { | ||
const { values } = unpackTx(encode(buffer, Encoding.Transaction), Tag.Mtree); | ||
return Object.fromEntries(values | ||
// TODO: remove after resolving https://github.com/aeternity/aeternity/issues/4066 | ||
.filter(({ key }) => encoding !== Encoding.ContractAddress || key.length === 32) | ||
.map(({ key, value }) => [ | ||
encode(key, encoding), | ||
unpackTx(encode(value, Encoding.Transaction), tag), | ||
])) as Record<Encoded.Generic<E>, any>; | ||
}, | ||
|
||
recursiveType: true, | ||
}; | ||
} |
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,32 @@ | ||
import { Tag } from '../constants'; | ||
import { encode, Encoding, decode } from '../../../utils/encoder'; | ||
import type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index'; | ||
|
||
type TagWrapping = Tag.AccountsMtree | Tag.CallsMtree | Tag.ChannelsMtree | Tag.ContractsMtree | ||
| Tag.NameserviceMtree | Tag.OraclesMtree; | ||
|
||
export default function genWrappedField<T extends TagWrapping>(tag: T): { | ||
serialize: ( | ||
// TODO: replace with `(TxParams & { tag: T })['payload']`, | ||
// but fix TS2502 value is referenced directly or indirectly in its own type annotation | ||
value: any, options: { buildTx: typeof buildTxType } | ||
) => Buffer; | ||
deserialize: ( | ||
value: Buffer, options: { unpackTx: typeof unpackTxType }, | ||
// TODO: replace with `(TxUnpacked & { tag: T })['payload']`, | ||
// TS2577 Return type annotation circularly references itself | ||
) => any; | ||
recursiveType: true; | ||
} { | ||
return { | ||
serialize(payload, { buildTx }) { | ||
return decode(buildTx({ tag, payload })); | ||
}, | ||
|
||
deserialize(buffer, { unpackTx }) { | ||
return unpackTx<TagWrapping>(encode(buffer, Encoding.Transaction), tag).payload; | ||
}, | ||
|
||
recursiveType: true, | ||
}; | ||
} |
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.