@aresrpg/sui-checkpoint-reader
Advanced tools
Comparing version
{ | ||
"name": "@aresrpg/sui-checkpoint-reader", | ||
"version": "3.3.3", | ||
"version": "4.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
import { bcs } from '@mysten/bcs' | ||
import { | ||
CheckpointContents, | ||
CheckpointSummary, | ||
Data, | ||
EmptySignInfo, | ||
Owner, | ||
SenderSignedData, | ||
StructTag, | ||
SuiAddress, | ||
TransactionDigest, | ||
TransactionEffects, | ||
} from './generated/bcs-sui.js' | ||
const Envelope = (name, data, auth_signature) => | ||
bcs.struct(name, { | ||
data, | ||
auth_signature, | ||
}) | ||
const IntentScope = bcs.u8() | ||
const IntentVersion = bcs.u8() | ||
const AppId = bcs.u8() | ||
const EpochId = bcs.u64() | ||
@@ -39,20 +26,2 @@ const Intent = bcs.struct('Intent', { | ||
const AggregateAuthoritySignature = bcs.fixedArray(48, bcs.u8()) | ||
const SuiBitmap = bcs.vector(bcs.u8()) | ||
const AuthorityStrongQuorumSignInfo = bcs.struct( | ||
'AuthorityStrongQuorumSignInfo', | ||
{ | ||
epoch: EpochId, | ||
signature: AggregateAuthoritySignature, | ||
signers_map: SuiBitmap, | ||
}, | ||
) | ||
const CertifiedCheckpointSummary = Envelope( | ||
'CertifiedCheckpointSummary', | ||
CheckpointSummary, | ||
AuthorityStrongQuorumSignInfo, | ||
) | ||
const SuiObject = bcs.struct('SuiObject', { | ||
@@ -65,24 +34,2 @@ data: Data, | ||
const Transaction = Envelope('Transaction', SenderSignedData, EmptySignInfo) | ||
const TransactionEvent = bcs.struct('TransactionEvent', { | ||
package_id: SuiAddress, | ||
transaction_module: bcs.string(), | ||
sender: SuiAddress, | ||
type: StructTag, | ||
contents: bcs.vector(bcs.u8()), | ||
}) | ||
const TransactionEvents = bcs.struct('TransactionEvents', { | ||
data: bcs.vector(TransactionEvent), | ||
}) | ||
const CheckpointTransaction = bcs.struct('CheckpointTransaction', { | ||
transaction: Transaction, | ||
effects: TransactionEffects, | ||
events: bcs.option(TransactionEvents), | ||
input_objects: bcs.vector(SuiObject), | ||
output_objects: bcs.vector(SuiObject), | ||
}) | ||
const FileType = bcs.enum('FileType', { | ||
@@ -126,7 +73,1 @@ Object: null, | ||
}) | ||
export const CheckpointData = bcs.struct('CheckpointData', { | ||
checkpoint_summary: CertifiedCheckpointSummary, | ||
checkpoint_contents: CheckpointContents, | ||
transactions: bcs.vector(CheckpointTransaction), | ||
}) |
@@ -5,3 +5,3 @@ import { writeFile } from 'fs/promises' | ||
const VERSION = 'testnet-v1.33.2' | ||
const VERSION = 'main' | ||
const YAML_URL = | ||
@@ -16,2 +16,45 @@ 'https://raw.githubusercontent.com/MystenLabs/sui/{version}/crates/sui-core/tests/staged/sui.yaml' | ||
function parse_function_type(type_string) { | ||
const clean = str => str.replace(/sui_types::/g, '') | ||
const parse_type = type => { | ||
const match = type.match(/^([\w:]+)(?:<(.+)>)?$/) | ||
if (!match) { | ||
return null | ||
} | ||
const [, type_name, sub_types] = match | ||
const result = { type: type_name.split('::').pop(), subtypes: [] } | ||
if (sub_types) { | ||
let depth = 0 | ||
let current = '' | ||
for (let i = 0; i < sub_types.length; i++) { | ||
const char = sub_types[i] | ||
if (char === '<') depth++ | ||
else if (char === '>') depth-- | ||
if (char === ',' && depth === 0) { | ||
if (current.trim()) { | ||
result.subtypes.push(parse_type(current.trim())) | ||
} | ||
current = '' | ||
} else { | ||
current += char | ||
} | ||
} | ||
if (current.trim()) { | ||
result.subtypes.push(parse_type(current.trim())) | ||
} | ||
} | ||
return result | ||
} | ||
const cleaned_string = clean(type_string) | ||
return parse_type(cleaned_string) | ||
} | ||
function generate_bcs_types(parsed_yaml) { | ||
@@ -21,2 +64,3 @@ const typeGraph = new Map() | ||
const orderedTypes = [] | ||
const functionTypes = new Map() | ||
@@ -45,8 +89,34 @@ // Build dependency graph | ||
// Generate ordered content | ||
const content = orderedTypes.map( | ||
name => `export const ${name} = ${parse_type(parsed_yaml[name], name)};`, | ||
orderedTypes | ||
.filter(name => name.includes('sui_types::')) | ||
.forEach(name => { | ||
const { type, subtypes } = parse_function_type(name) | ||
const type_content = parsed_yaml[name] | ||
if (!functionTypes.has(type)) { | ||
functionTypes.set(type, { name, subtypes, content: type_content }) | ||
} | ||
}) | ||
const function_types = Array.from(functionTypes.entries()).map( | ||
([type, { name, subtypes, content }]) => { | ||
const params = content.STRUCT | ||
? content.STRUCT.map(obj => Object.keys(obj)[0]).join(', ') | ||
: 'data' | ||
return `const ${type} = (name, ${params}) => | ||
${parse_type(content, name)}` | ||
}, | ||
) | ||
return `import { bcs } from '@mysten/bcs';\n\n${content.join('\n')}` | ||
// Generate ordered content | ||
const content = orderedTypes | ||
.filter(name => !name.includes('sui_types::')) | ||
.map( | ||
name => `export const ${name} = ${parse_type(parsed_yaml[name], name)};`, | ||
) | ||
return `import { bcs } from '@mysten/bcs'; | ||
${function_types.join('\n\n')} | ||
${content.join('\n')}` | ||
} | ||
@@ -71,7 +141,20 @@ | ||
function parse_type(type, name = null) { | ||
function parse_type(type, name = 'name') { | ||
if (name?.includes('sui_types::')) { | ||
const { type: funcName } = parse_function_type(name) | ||
const params = type.STRUCT | ||
? type.STRUCT.map(obj => Object.keys(obj)[0]).join(', ') | ||
: 'data' | ||
return `${funcName}('${name}', ${params})` | ||
} | ||
if (typeof type === 'object') { | ||
if (type.NEWTYPESTRUCT) return parse_type(type.NEWTYPESTRUCT, name) | ||
if (type.STRUCT) return parse_struct(type.STRUCT, name) | ||
if (type.TYPENAME) return type.TYPENAME | ||
if (type.TYPENAME) { | ||
const parsed = parse_function_type(type.TYPENAME) | ||
if (parsed.subtypes.length > 0) { | ||
return `${parsed.type}('${name}', ${parsed.subtypes.map(st => st.type).join(', ')})` | ||
} | ||
return type.TYPENAME | ||
} | ||
if (type.SEQ) return `bcs.vector(${parse_type(type.SEQ, name)})` | ||
@@ -141,4 +224,5 @@ if (type.OPTION) return `bcs.option(${parse_type(type.OPTION, name)})` | ||
const definitions = await get_type_definitions() | ||
await writeFile('./src/types.json', JSON.stringify(definitions, null, 2)) | ||
console.log('Generating BCS types...') | ||
await writeFile('./src/generated/bcs-sui.js', generate_bcs_types(definitions)) |
import { bcs } from '@mysten/bcs' | ||
const Envelope = (name, data, auth_signature) => | ||
bcs.struct(name, { | ||
data, | ||
auth_signature, | ||
}) | ||
@@ -37,2 +42,7 @@ export const AccountAddress = bcs.fixedArray(32, bcs.u8()) | ||
export const AuthorityPublicKeyBytes = bcs.vector(bcs.u8()) | ||
export const AuthorityQuorumSignInfo = bcs.struct('AuthorityQuorumSignInfo', { | ||
epoch: bcs.u64(), | ||
signature: bcs.fixedArray(48, bcs.u8()), | ||
signers_map: bcs.vector(bcs.u8()), | ||
}) | ||
export const ObjectID = AccountAddress | ||
@@ -119,4 +129,8 @@ export const Digest = bcs.vector(bcs.u8()) | ||
}) | ||
export const Identifier = bcs.string() | ||
export const TypeTag = bcs.enum('TypeTag', { | ||
export const Intent = bcs.struct('Intent', { | ||
scope: bcs.u8(), | ||
version: bcs.u8(), | ||
app_id: bcs.u8(), | ||
}) | ||
export const TypeInput = bcs.enum('TypeInput', { | ||
bool: null, | ||
@@ -128,4 +142,4 @@ u8: null, | ||
signer: null, | ||
vector: bcs.lazy(() => TypeTag), | ||
struct: bcs.lazy(() => StructTag), | ||
vector: bcs.lazy(() => TypeInput), | ||
struct: bcs.lazy(() => StructInput), | ||
u16: null, | ||
@@ -135,13 +149,13 @@ u32: null, | ||
}) | ||
export const StructTag = bcs.struct('StructTag', { | ||
export const StructInput = bcs.struct('StructInput', { | ||
address: AccountAddress, | ||
module: Identifier, | ||
name: Identifier, | ||
type_args: bcs.vector(TypeTag), | ||
module: bcs.string(), | ||
name: bcs.string(), | ||
type_args: bcs.vector(TypeInput), | ||
}) | ||
export const ProgrammableMoveCall = bcs.struct('ProgrammableMoveCall', { | ||
package: ObjectID, | ||
module: Identifier, | ||
function: Identifier, | ||
type_arguments: bcs.vector(TypeTag), | ||
module: bcs.string(), | ||
function: bcs.string(), | ||
type_arguments: bcs.vector(TypeInput), | ||
arguments: bcs.vector(Argument), | ||
@@ -155,3 +169,3 @@ }) | ||
Publish: bcs.tuple([bcs.vector(bcs.vector(bcs.u8())), bcs.vector(ObjectID)]), | ||
MakeMoveVec: bcs.tuple([bcs.option(TypeTag), bcs.vector(Argument)]), | ||
MakeMoveVec: bcs.tuple([bcs.option(TypeInput), bcs.vector(Argument)]), | ||
Upgrade: bcs.tuple([ | ||
@@ -164,67 +178,25 @@ bcs.vector(bcs.vector(bcs.u8())), | ||
}) | ||
export const CommandArgumentError = bcs.enum('CommandArgumentError', { | ||
TypeMismatch: null, | ||
InvalidBCSBytes: null, | ||
InvalidUsageOfPureArg: null, | ||
InvalidArgumentToPrivateEntryFunction: null, | ||
IndexOutOfBounds: bcs.struct('IndexOutOfBounds', { idx: bcs.u16() }), | ||
SecondaryIndexOutOfBounds: bcs.struct('SecondaryIndexOutOfBounds', { | ||
result_idx: bcs.u16(), | ||
secondary_idx: bcs.u16(), | ||
}), | ||
InvalidResultArity: bcs.struct('InvalidResultArity', { | ||
result_idx: bcs.u16(), | ||
}), | ||
InvalidGasCoinUsage: null, | ||
InvalidValueUsage: null, | ||
InvalidObjectByValue: null, | ||
InvalidObjectByMutRef: null, | ||
SharedObjectOperationNotAllowed: null, | ||
export const ProgrammableTransaction = bcs.struct('ProgrammableTransaction', { | ||
inputs: bcs.vector(CallArg), | ||
commands: bcs.vector(Command), | ||
}) | ||
export const ZkLoginAuthenticatorAsBytes = bcs.vector(bcs.u8()) | ||
export const CompressedSignature = bcs.enum('CompressedSignature', { | ||
Ed25519: bcs.fixedArray(64, bcs.u8()), | ||
Secp256k1: bcs.fixedArray(64, bcs.u8()), | ||
Secp256r1: bcs.fixedArray(64, bcs.u8()), | ||
ZkLogin: ZkLoginAuthenticatorAsBytes, | ||
export const TypeTag = bcs.enum('TypeTag', { | ||
bool: null, | ||
u8: null, | ||
u64: null, | ||
u128: null, | ||
address: null, | ||
signer: null, | ||
vector: bcs.lazy(() => TypeTag), | ||
struct: bcs.lazy(() => StructTag), | ||
u16: null, | ||
u32: null, | ||
u256: null, | ||
}) | ||
export const CongestedObjects = bcs.vector(ObjectID) | ||
export const ConsensusCommitDigest = Digest | ||
export const ConsensusCommitPrologue = bcs.struct('ConsensusCommitPrologue', { | ||
epoch: bcs.u64(), | ||
round: bcs.u64(), | ||
commit_timestamp_ms: bcs.u64(), | ||
export const StructTag = bcs.struct('StructTag', { | ||
address: AccountAddress, | ||
module: bcs.string(), | ||
name: bcs.string(), | ||
type_args: bcs.vector(TypeTag), | ||
}) | ||
export const ConsensusCommitPrologueV2 = bcs.struct( | ||
'ConsensusCommitPrologueV2', | ||
{ | ||
epoch: bcs.u64(), | ||
round: bcs.u64(), | ||
commit_timestamp_ms: bcs.u64(), | ||
consensus_commit_digest: ConsensusCommitDigest, | ||
}, | ||
) | ||
export const ConsensusDeterminedVersionAssignments = bcs.enum( | ||
'ConsensusDeterminedVersionAssignments', | ||
{ | ||
CancelledTransactions: bcs.vector( | ||
bcs.tuple([ | ||
TransactionDigest, | ||
bcs.vector(bcs.tuple([ObjectID, SequenceNumber])), | ||
]), | ||
), | ||
}, | ||
) | ||
export const ConsensusCommitPrologueV3 = bcs.struct( | ||
'ConsensusCommitPrologueV3', | ||
{ | ||
epoch: bcs.u64(), | ||
round: bcs.u64(), | ||
sub_dag_index: bcs.option(bcs.u64()), | ||
commit_timestamp_ms: bcs.u64(), | ||
consensus_commit_digest: ConsensusCommitDigest, | ||
consensus_determined_version_assignments: | ||
ConsensusDeterminedVersionAssignments, | ||
}, | ||
) | ||
export const MoveObjectType_ = bcs.enum('MoveObjectType_', { | ||
@@ -260,8 +232,2 @@ Other: StructTag, | ||
export const Data = bcs.enum('Data', { Move: MoveObject, Package: MovePackage }) | ||
export const DeleteKind = bcs.enum('DeleteKind', { | ||
Normal: null, | ||
UnwrapThenDelete: null, | ||
Wrap: null, | ||
}) | ||
export const EffectsAuxDataDigest = Digest | ||
export const SuiAddress = bcs.fixedArray(32, bcs.u8()) | ||
@@ -274,22 +240,13 @@ export const Owner = bcs.enum('Owner', { | ||
}) | ||
export const ObjectIn = bcs.enum('ObjectIn', { | ||
NotExist: null, | ||
Exist: bcs.tuple([bcs.tuple([SequenceNumber, ObjectDigest]), Owner]), | ||
export const GenesisObject = bcs.enum('GenesisObject', { | ||
RawObject: bcs.struct('RawObject', { data: Data, owner: Owner }), | ||
}) | ||
export const ObjectOut = bcs.enum('ObjectOut', { | ||
NotExist: null, | ||
ObjectWrite: bcs.tuple([ObjectDigest, Owner]), | ||
PackageWrite: bcs.tuple([SequenceNumber, ObjectDigest]), | ||
export const GenesisTransaction = bcs.struct('GenesisTransaction', { | ||
objects: bcs.vector(GenesisObject), | ||
}) | ||
export const IDOperation = bcs.enum('IDOperation', { | ||
None: null, | ||
Created: null, | ||
Deleted: null, | ||
export const ConsensusCommitPrologue = bcs.struct('ConsensusCommitPrologue', { | ||
epoch: bcs.u64(), | ||
round: bcs.u64(), | ||
commit_timestamp_ms: bcs.u64(), | ||
}) | ||
export const EffectsObjectChange = bcs.struct('EffectsObjectChange', { | ||
input_state: ObjectIn, | ||
output_state: ObjectOut, | ||
id_operation: IDOperation, | ||
}) | ||
export const EmptySignInfo = bcs.struct('EmptySignInfo', {}) | ||
export const EndOfEpochTransactionKind = bcs.enum('EndOfEpochTransactionKind', { | ||
@@ -304,17 +261,2 @@ ChangeEpoch, | ||
}) | ||
export const Intent = bcs.struct('Intent', { | ||
scope: bcs.u8(), | ||
version: bcs.u8(), | ||
app_id: bcs.u8(), | ||
}) | ||
export const ProgrammableTransaction = bcs.struct('ProgrammableTransaction', { | ||
inputs: bcs.vector(CallArg), | ||
commands: bcs.vector(Command), | ||
}) | ||
export const GenesisObject = bcs.enum('GenesisObject', { | ||
RawObject: bcs.struct('RawObject', { data: Data, owner: Owner }), | ||
}) | ||
export const GenesisTransaction = bcs.struct('GenesisTransaction', { | ||
objects: bcs.vector(GenesisObject), | ||
}) | ||
export const RandomnessRound = bcs.u64() | ||
@@ -327,2 +269,35 @@ export const RandomnessStateUpdate = bcs.struct('RandomnessStateUpdate', { | ||
}) | ||
export const ConsensusCommitDigest = Digest | ||
export const ConsensusCommitPrologueV2 = bcs.struct( | ||
'ConsensusCommitPrologueV2', | ||
{ | ||
epoch: bcs.u64(), | ||
round: bcs.u64(), | ||
commit_timestamp_ms: bcs.u64(), | ||
consensus_commit_digest: ConsensusCommitDigest, | ||
}, | ||
) | ||
export const ConsensusDeterminedVersionAssignments = bcs.enum( | ||
'ConsensusDeterminedVersionAssignments', | ||
{ | ||
CancelledTransactions: bcs.vector( | ||
bcs.tuple([ | ||
TransactionDigest, | ||
bcs.vector(bcs.tuple([ObjectID, SequenceNumber])), | ||
]), | ||
), | ||
}, | ||
) | ||
export const ConsensusCommitPrologueV3 = bcs.struct( | ||
'ConsensusCommitPrologueV3', | ||
{ | ||
epoch: bcs.u64(), | ||
round: bcs.u64(), | ||
sub_dag_index: bcs.option(bcs.u64()), | ||
commit_timestamp_ms: bcs.u64(), | ||
consensus_commit_digest: ConsensusCommitDigest, | ||
consensus_determined_version_assignments: | ||
ConsensusDeterminedVersionAssignments, | ||
}, | ||
) | ||
export const TransactionKind = bcs.enum('TransactionKind', { | ||
@@ -367,9 +342,6 @@ ProgrammableTransaction, | ||
export const SenderSignedData = bcs.vector(SenderSignedTransaction) | ||
export const Envelope = bcs.struct('Envelope', { | ||
data: SenderSignedData, | ||
auth_signature: EmptySignInfo, | ||
}) | ||
export const EmptySignInfo = bcs.struct('EmptySignInfo', {}) | ||
export const ModuleId = bcs.struct('ModuleId', { | ||
address: AccountAddress, | ||
name: Identifier, | ||
name: bcs.string(), | ||
}) | ||
@@ -383,2 +355,21 @@ export const MoveLocation = bcs.struct('MoveLocation', { | ||
export const MoveLocationOpt = bcs.option(MoveLocation) | ||
export const CommandArgumentError = bcs.enum('CommandArgumentError', { | ||
TypeMismatch: null, | ||
InvalidBCSBytes: null, | ||
InvalidUsageOfPureArg: null, | ||
InvalidArgumentToPrivateEntryFunction: null, | ||
IndexOutOfBounds: bcs.struct('IndexOutOfBounds', { idx: bcs.u16() }), | ||
SecondaryIndexOutOfBounds: bcs.struct('SecondaryIndexOutOfBounds', { | ||
result_idx: bcs.u16(), | ||
secondary_idx: bcs.u16(), | ||
}), | ||
InvalidResultArity: bcs.struct('InvalidResultArity', { | ||
result_idx: bcs.u16(), | ||
}), | ||
InvalidGasCoinUsage: null, | ||
InvalidValueUsage: null, | ||
InvalidObjectByValue: null, | ||
InvalidObjectByMutRef: null, | ||
SharedObjectOperationNotAllowed: null, | ||
}) | ||
export const TypeArgumentError = bcs.enum('TypeArgumentError', { | ||
@@ -405,2 +396,3 @@ TypeNotFound: null, | ||
}) | ||
export const CongestedObjects = bcs.vector(ObjectID) | ||
export const ExecutionFailureStatus = bcs.enum('ExecutionFailureStatus', { | ||
@@ -519,2 +511,21 @@ InsufficientGas: null, | ||
}) | ||
export const ObjectIn = bcs.enum('ObjectIn', { | ||
NotExist: null, | ||
Exist: bcs.tuple([bcs.tuple([SequenceNumber, ObjectDigest]), Owner]), | ||
}) | ||
export const ObjectOut = bcs.enum('ObjectOut', { | ||
NotExist: null, | ||
ObjectWrite: bcs.tuple([ObjectDigest, Owner]), | ||
PackageWrite: bcs.tuple([SequenceNumber, ObjectDigest]), | ||
}) | ||
export const IDOperation = bcs.enum('IDOperation', { | ||
None: null, | ||
Created: null, | ||
Deleted: null, | ||
}) | ||
export const EffectsObjectChange = bcs.struct('EffectsObjectChange', { | ||
input_state: ObjectIn, | ||
output_state: ObjectOut, | ||
id_operation: IDOperation, | ||
}) | ||
export const UnchangedSharedKind = bcs.enum('UnchangedSharedKind', { | ||
@@ -527,2 +538,3 @@ ReadOnlyRoot: bcs.tuple([SequenceNumber, ObjectDigest]), | ||
}) | ||
export const EffectsAuxDataDigest = Digest | ||
export const TransactionEffectsV2 = bcs.struct('TransactionEffectsV2', { | ||
@@ -547,4 +559,48 @@ status: ExecutionStatus, | ||
}) | ||
export const Event = bcs.struct('Event', { | ||
package_id: ObjectID, | ||
transaction_module: bcs.string(), | ||
sender: SuiAddress, | ||
type: StructTag, | ||
contents: bcs.vector(bcs.u8()), | ||
}) | ||
export const TransactionEvents = bcs.struct('TransactionEvents', { | ||
data: bcs.vector(Event), | ||
}) | ||
export const Object = bcs.struct('Object', { | ||
data: Data, | ||
owner: Owner, | ||
previous_transaction: TransactionDigest, | ||
storage_rebate: bcs.u64(), | ||
}) | ||
export const CheckpointTransaction = bcs.struct('CheckpointTransaction', { | ||
transaction: Envelope('transaction', SenderSignedData, EmptySignInfo), | ||
effects: TransactionEffects, | ||
events: bcs.option(TransactionEvents), | ||
input_objects: bcs.vector(Object), | ||
output_objects: bcs.vector(Object), | ||
}) | ||
export const CheckpointData = bcs.struct('CheckpointData', { | ||
checkpoint_summary: Envelope( | ||
'checkpoint_summary', | ||
CheckpointSummary, | ||
AuthorityQuorumSignInfo, | ||
), | ||
checkpoint_contents: CheckpointContents, | ||
transactions: bcs.vector(CheckpointTransaction), | ||
}) | ||
export const ZkLoginAuthenticatorAsBytes = bcs.vector(bcs.u8()) | ||
export const CompressedSignature = bcs.enum('CompressedSignature', { | ||
Ed25519: bcs.fixedArray(64, bcs.u8()), | ||
Secp256k1: bcs.fixedArray(64, bcs.u8()), | ||
Secp256r1: bcs.fixedArray(64, bcs.u8()), | ||
ZkLogin: ZkLoginAuthenticatorAsBytes, | ||
}) | ||
export const DeleteKind = bcs.enum('DeleteKind', { | ||
Normal: null, | ||
UnwrapThenDelete: null, | ||
Wrap: null, | ||
}) | ||
export const ExecutionData = bcs.struct('ExecutionData', { | ||
transaction: Envelope, | ||
transaction: Envelope('transaction', SenderSignedData, EmptySignInfo), | ||
effects: TransactionEffects, | ||
@@ -551,0 +607,0 @@ }) |
@@ -12,4 +12,3 @@ import { setInterval, setTimeout } from 'timers/promises' | ||
import { get_local_checkpoints } from './get_local_checkpoints.js' | ||
import { SuiAddress } from './generated/bcs-sui.js' | ||
import { CheckpointData } from './bcs-checkpoints.js' | ||
import { SuiAddress, CheckpointData } from './generated/bcs-sui.js' | ||
@@ -45,13 +44,13 @@ function mapper(object_source, mappings) { | ||
name, | ||
type_params = [], | ||
type_args = [], | ||
$kind, | ||
...rest | ||
}) { | ||
if ($kind && $kind !== 'Struct') { | ||
switch ($kind) { | ||
case 'Address': | ||
if ($kind && $kind.toLowerCase() !== 'struct') { | ||
switch ($kind.toLowerCase()) { | ||
case 'address': | ||
return SuiAddress | ||
case 'Vector': | ||
if (rest.Vector.Struct) return find_nested_bcs(rest.Vector.Struct) | ||
return bcs.vector(bcs[rest.Vector.$kind.toLowerCase()]) | ||
case 'vector': | ||
if (rest.vector.struct) return find_nested_bcs(rest.vector.struct) | ||
return bcs.vector(bcs[rest.vector.$kind.toLowerCase()]()) | ||
default: | ||
@@ -66,6 +65,6 @@ return bcs[$kind.toLowerCase()]() | ||
if (type_params.length) { | ||
const nested_bcs = type_params.map(({ Struct, ...rest }) => { | ||
if (!Struct) return find_nested_bcs(rest) | ||
return find_nested_bcs(Struct) | ||
if (type_args.length) { | ||
const nested_bcs = type_args.map(({ struct, ...rest }) => { | ||
if (!struct) return find_nested_bcs(rest) | ||
return find_nested_bcs(struct) | ||
}) | ||
@@ -83,24 +82,26 @@ | ||
if (!found_bcs?.parse) return | ||
const parsed = found_bcs.parse(new Uint8Array(contents)) | ||
const { id: { id: { bytes = undefined } = {} } = {}, ...rest } = mapper( | ||
parsed, | ||
{ | ||
bytes: b => { | ||
if (Array.isArray(b)) return Buffer.from(b).toString('utf8') | ||
return b | ||
try { | ||
const parsed = found_bcs.parse(new Uint8Array(contents)) | ||
const { id: { id: { bytes = undefined } = {} } = {}, ...rest } = mapper( | ||
parsed, | ||
{ | ||
bytes: b => { | ||
if (Array.isArray(b)) return Buffer.from(b).toString('utf8') | ||
return b | ||
}, | ||
}, | ||
}, | ||
) | ||
return { | ||
...(bytes && { id: `0x${bytes}` }), | ||
...Object.fromEntries( | ||
Object.entries(rest).map(([key, value]) => { | ||
// @ts-ignore | ||
if (value.bytes) return [key, value.bytes] | ||
return [key, value] | ||
}), | ||
), | ||
) | ||
return { | ||
...(bytes && { id: `0x${bytes}` }), | ||
...Object.fromEntries( | ||
Object.entries(rest).map(([key, value]) => { | ||
// @ts-ignore | ||
if (value.bytes) return [key, value.bytes] | ||
return [key, value] | ||
}), | ||
), | ||
} | ||
} catch (error) { | ||
console.dir({ found_bcs }, { depth: Infinity }) | ||
throw error | ||
} | ||
@@ -137,3 +138,3 @@ } | ||
// @ts-ignore | ||
Other: { address, module, name, type_params = [] } = {}, | ||
Other: { address, module, name, type_args = [] } = {}, | ||
}, | ||
@@ -145,3 +146,3 @@ has_public_transfer, | ||
const parsed_type_params = parse_type_param(type_params) | ||
const parsed_type_args = parse_type_args(type_args) | ||
@@ -153,2 +154,3 @@ if (Other) { | ||
}) | ||
const digest = parsed_content | ||
@@ -165,4 +167,4 @@ ? get_object_digest(parsed_content.id) | ||
previous_transaction, | ||
...(type_params?.length && { | ||
type_params: `${address}::${module}::${name}<${parsed_type_params}>`, | ||
...(type_args?.length && { | ||
type_args: `${address}::${module}::${name}<${parsed_type_args}>`, | ||
}), | ||
@@ -182,4 +184,4 @@ contents: parsed_content ?? contents, | ||
const has_sub_type = type.type_params?.length | ||
const parsed_type = parse_type_param(type.type_params) | ||
const has_sub_type = type.type_args?.length | ||
const parsed_type = parse_type_args(type.type_args) | ||
const event_type = `${type.address}::${type.module}::${type.name}${has_sub_type ? `<${parsed_type}>` : ''}` | ||
@@ -216,16 +218,15 @@ const base_config = known_types[type.address]?.[type.module]?.[type.name] | ||
function parse_type_param(params = []) { | ||
function parse_type_args(params = []) { | ||
if (!params.length) return '' | ||
return params.reduce((result, { Struct, $kind }) => { | ||
if (!Struct) return `${result}, ${$kind.toLowerCase()}` | ||
const { address, module, name, type_params = [] } = Struct | ||
return params.reduce((result, { struct, $kind }) => { | ||
if (!struct) return `${result}, ${$kind.toLowerCase()}` | ||
const { address, module, name, type_args = [] } = struct | ||
const typename = `${address}::${module}::${name}` | ||
if (!result) | ||
if (type_params.length) | ||
return `${typename}<${parse_type_param(type_params)}>` | ||
if (type_args.length) return `${typename}<${parse_type_args(type_args)}>` | ||
else return typename | ||
if (type_params.length) | ||
return `${result}, ${typename}<${parse_type_param(type_params)}>` | ||
if (type_args.length) | ||
return `${result}, ${typename}<${parse_type_args(type_args)}>` | ||
return `${result}, ${typename}` | ||
@@ -232,0 +233,0 @@ }, '') |
@@ -59,3 +59,6 @@ import { ClassicLevel } from 'classic-level' | ||
const raw_objects = objects.map(({ Normal }) => Normal).filter(Boolean) | ||
const raw_objects = objects | ||
.map(({ Normal }) => Normal) | ||
.filter(Boolean) | ||
.filter(({ data }) => !data.Move?.type?.GasCoin) | ||
@@ -62,0 +65,0 @@ let batches = 0 |
@@ -7,4 +7,4 @@ import { read_checkpoints } from '../src/index.js' | ||
process_checkpoint: async (data, index) => { | ||
console.dir({ data, index }) | ||
console.dir({ data, index }, { depth: Infinity }) | ||
}, | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
729912
-15%33
-5.71%19398
-4.14%