You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
import type { ErrorType } from '../../errors/utils.js'
|
|
import type { Hex } from '../../types/misc.js'
|
|
import { type SizeErrorType, size } from '../../utils/data/size.js'
|
|
import { type SliceErrorType, slice } from '../../utils/data/slice.js'
|
|
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
|
|
|
export type OpaqueDataToDepositDataParameters = Hex
|
|
|
|
export type OpaqueDataToDepositDataReturnType = {
|
|
mint: bigint
|
|
value: bigint
|
|
gas: bigint
|
|
isCreation: boolean
|
|
data: Hex
|
|
}
|
|
|
|
export type OpaqueDataToDepositDataErrorType =
|
|
| SliceErrorType
|
|
| SizeErrorType
|
|
| ErrorType
|
|
|
|
export function opaqueDataToDepositData(
|
|
opaqueData: Hex,
|
|
): OpaqueDataToDepositDataReturnType {
|
|
let offset = 0
|
|
const mint = slice(opaqueData, offset, offset + 32)
|
|
offset += 32
|
|
const value = slice(opaqueData, offset, offset + 32)
|
|
offset += 32
|
|
const gas = slice(opaqueData, offset, offset + 8)
|
|
offset += 8
|
|
const isCreation = BigInt(slice(opaqueData, offset, offset + 1)) === 1n
|
|
offset += 1
|
|
const data =
|
|
offset > size(opaqueData) - 1
|
|
? '0x'
|
|
: slice(opaqueData, offset, opaqueData.length)
|
|
return {
|
|
mint: hexToBigInt(mint),
|
|
value: hexToBigInt(value),
|
|
gas: hexToBigInt(gas),
|
|
isCreation,
|
|
data,
|
|
}
|
|
}
|