feat(events): прокинуть полный SHiP action_trace в ActionEvent — transaction_id, creator_action_ordinal, receipt.auth_sequence, console/elapsed/context_free/account_ram_deltas
ActionEvent отдавал только подмножество трассировки. Потребители (контроллер ЦК: ledger2 связывает операцию с родительским apply по transaction_id + action_ordinal/ creator_action_ordinal; blockchain-explorer показывает receipt/ram-deltas/console) требуют полный паритет с прежним транспортом. Данные уже декодируются wharfkit'ом — ship-reader их просто не извлекал. ship-reader: ShipTrace += creatorActionOrdinal/contextFree/elapsed/console/ accountRamDeltas; ActionReceipt += authSequence; извлечение в ShipProtocol из action_trace (auth_sequence поддержан и как объект, и как кортеж). parser2: BlockProcessor копирует поля в ActionEvent; типы и тесты обновлены. ship-reader 0.1.0→0.2.0, parser2 1.0.3→1.1.0. Тесты: ship-reader 51, parser2 205 — зелёные. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@coopenomics/parser2",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.0",
|
||||
"description": "Universal EOSIO/Antelope SHiP-to-Redis blockchain indexer (parser)",
|
||||
"license": "MIT",
|
||||
"author": "Coopenomics contributors",
|
||||
|
||||
@@ -136,13 +136,19 @@ export class BlockProcessor {
|
||||
block_num: blockNum,
|
||||
block_time: blockTime,
|
||||
block_id: blockId,
|
||||
transaction_id: trace.transactionId,
|
||||
account: trace.account,
|
||||
name: trace.name,
|
||||
authorization: [...trace.authorization],
|
||||
data,
|
||||
action_ordinal: trace.actionOrdinal,
|
||||
creator_action_ordinal: trace.creatorActionOrdinal,
|
||||
global_sequence: trace.globalSequence,
|
||||
receipt: trace.receipt,
|
||||
context_free: trace.contextFree,
|
||||
elapsed: trace.elapsed,
|
||||
console: trace.console,
|
||||
account_ram_deltas: [...trace.accountRamDeltas],
|
||||
}
|
||||
|
||||
actionEvents.push({ ...partial, event_id: computeEventId(partial) })
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* повторные доставки.
|
||||
*/
|
||||
|
||||
import type { ActionAuthorization, ActionReceipt } from '@coopenomics/coopos-ship-reader'
|
||||
import type { ActionAuthorization, ActionReceipt, AccountRamDelta } from '@coopenomics/coopos-ship-reader'
|
||||
|
||||
/** Событие вызова смарт-контракта (inline action). */
|
||||
export interface ActionEvent {
|
||||
@@ -20,6 +20,8 @@ export interface ActionEvent {
|
||||
/** ISO-8601 время блока из трассировки транзакции. */
|
||||
block_time: string
|
||||
block_id: string
|
||||
/** Хеш транзакции, в которой исполнено действие. */
|
||||
transaction_id: string
|
||||
/** Аккаунт-владелец контракта (account). */
|
||||
account: string
|
||||
/** Имя действия (action name). */
|
||||
@@ -29,10 +31,20 @@ export interface ActionEvent {
|
||||
data: Record<string, unknown>
|
||||
/** Порядковый номер действия внутри транзакции (1-based). */
|
||||
action_ordinal: number
|
||||
/** Порядковый номер родительского (создавшего) действия; 0 — если действие верхнего уровня. */
|
||||
creator_action_ordinal: number
|
||||
/** Глобальная уникальная последовательность — монотонный счётчик действий в цепи. */
|
||||
global_sequence: bigint
|
||||
/** Квитанция об исполнении; null если нет трассировки. */
|
||||
receipt: ActionReceipt | null
|
||||
/** Является ли действие context-free. */
|
||||
context_free: boolean
|
||||
/** Время исполнения действия в микросекундах. */
|
||||
elapsed: number
|
||||
/** Консольный вывод действия (eosio::print и т.п.). */
|
||||
console: string
|
||||
/** Изменения RAM по аккаунтам в результате действия. */
|
||||
account_ram_deltas: AccountRamDelta[]
|
||||
}
|
||||
|
||||
/** Изменение строки в пользовательской таблице смарт-контракта (contract_row delta). */
|
||||
|
||||
@@ -57,8 +57,13 @@ function makeBlock(blockNum = 1, numTraces = 0, numDeltas = 0): ShipBlock {
|
||||
authorization: [{ actor: 'alice', permission: 'active' }],
|
||||
actRaw: new Uint8Array([1, 2, 3]),
|
||||
actionOrdinal: i + 1,
|
||||
creatorActionOrdinal: 0,
|
||||
globalSequence: BigInt(100 + i),
|
||||
receipt: null,
|
||||
contextFree: false,
|
||||
elapsed: 0,
|
||||
console: '',
|
||||
accountRamDeltas: [],
|
||||
blockNum,
|
||||
blockId: 'a'.repeat(64),
|
||||
blockTime: '2024-01-01T00:00:00.000',
|
||||
@@ -176,8 +181,13 @@ describe('BlockProcessor — ABI updates (Story 4.3)', () => {
|
||||
authorization: [],
|
||||
actRaw: new Uint8Array([1]),
|
||||
actionOrdinal: 1,
|
||||
creatorActionOrdinal: 0,
|
||||
globalSequence: BigInt(1),
|
||||
receipt: null,
|
||||
contextFree: false,
|
||||
elapsed: 0,
|
||||
console: '',
|
||||
accountRamDeltas: [],
|
||||
blockNum: 500,
|
||||
blockId: 'c'.repeat(64),
|
||||
blockTime: '2024-01-01T00:00:00.000',
|
||||
@@ -210,8 +220,13 @@ describe('BlockProcessor — ABI updates (Story 4.3)', () => {
|
||||
authorization: [],
|
||||
actRaw: new Uint8Array([1]),
|
||||
actionOrdinal: 1,
|
||||
creatorActionOrdinal: 0,
|
||||
globalSequence: BigInt(2),
|
||||
receipt: null,
|
||||
contextFree: false,
|
||||
elapsed: 0,
|
||||
console: '',
|
||||
accountRamDeltas: [],
|
||||
blockNum: 501,
|
||||
blockId: 'c'.repeat(64),
|
||||
blockTime: '2024-01-01T00:00:00.000',
|
||||
@@ -324,8 +339,8 @@ describe('BlockProcessor — native deltas (Epic 6)', () => {
|
||||
lastIrreversible: { blockNum: 20, blockId: 'b'.repeat(64) },
|
||||
prevBlock: null,
|
||||
traces: [
|
||||
{ account: 'eosio.token', name: 'transfer', authorization: [], actRaw: new Uint8Array([1]), actionOrdinal: 1, globalSequence: BigInt(1), receipt: null, blockNum: 20, blockId: 'b'.repeat(64), blockTime: '2024-01-01T00:00:00.000', transactionId: 'c'.repeat(64) },
|
||||
{ account: 'eosio.token', name: 'transfer', authorization: [], actRaw: new Uint8Array([1]), actionOrdinal: 2, globalSequence: BigInt(2), receipt: null, blockNum: 20, blockId: 'b'.repeat(64), blockTime: '2024-01-01T00:00:00.000', transactionId: 'c'.repeat(64) },
|
||||
{ account: 'eosio.token', name: 'transfer', authorization: [], actRaw: new Uint8Array([1]), actionOrdinal: 1, creatorActionOrdinal: 0, globalSequence: BigInt(1), receipt: null, contextFree: false, elapsed: 0, console: '', accountRamDeltas: [], blockNum: 20, blockId: 'b'.repeat(64), blockTime: '2024-01-01T00:00:00.000', transactionId: 'c'.repeat(64) },
|
||||
{ account: 'eosio.token', name: 'transfer', authorization: [], actRaw: new Uint8Array([1]), actionOrdinal: 2, creatorActionOrdinal: 0, globalSequence: BigInt(2), receipt: null, contextFree: false, elapsed: 0, console: '', accountRamDeltas: [], blockNum: 20, blockId: 'b'.repeat(64), blockTime: '2024-01-01T00:00:00.000', transactionId: 'c'.repeat(64) },
|
||||
],
|
||||
deltas: [
|
||||
{ name: 'contract_row', present: true, rowRaw: new Uint8Array([1]), code: 'eosio.token', scope: 'alice', table: 'accounts', primaryKey: '1' },
|
||||
@@ -355,7 +370,7 @@ describe('BlockProcessor — native deltas (Epic 6)', () => {
|
||||
head: { blockNum: 5, blockId: 'd'.repeat(64) },
|
||||
lastIrreversible: { blockNum: 5, blockId: 'd'.repeat(64) },
|
||||
prevBlock: null,
|
||||
traces: [{ account: 'eosio', name: 'newaccount', authorization: [], actRaw: new Uint8Array([1]), actionOrdinal: 1, globalSequence: BigInt(10), receipt: null, blockNum: 5, blockId: 'd'.repeat(64), blockTime: '2024-01-01T00:00:00.000', transactionId: 'e'.repeat(64) }],
|
||||
traces: [{ account: 'eosio', name: 'newaccount', authorization: [], actRaw: new Uint8Array([1]), actionOrdinal: 1, creatorActionOrdinal: 0, globalSequence: BigInt(10), receipt: null, contextFree: false, elapsed: 0, console: '', accountRamDeltas: [], blockNum: 5, blockId: 'd'.repeat(64), blockTime: '2024-01-01T00:00:00.000', transactionId: 'e'.repeat(64) }],
|
||||
deltas: [
|
||||
{ name: 'contract_row', present: true, rowRaw: new Uint8Array([1]), code: 'eosio', scope: 'eosio', table: 'global', primaryKey: '0' },
|
||||
{ name: 'permission' as never, present: true, rowRaw: new Uint8Array([1]) },
|
||||
|
||||
@@ -15,13 +15,19 @@ function makeAction(override: Partial<WithoutId<Extract<ParserEvent, { kind: 'ac
|
||||
block_num: 100,
|
||||
block_time: '2024-01-01T00:00:00.000',
|
||||
block_id: BLOCK_ID,
|
||||
transaction_id: 'tx0000000000000000000000000000000000000000000000000000000000000000',
|
||||
account: 'eosio.token',
|
||||
name: 'transfer',
|
||||
authorization: [],
|
||||
data: {},
|
||||
action_ordinal: 1,
|
||||
creator_action_ordinal: 0,
|
||||
global_sequence: 12345n,
|
||||
receipt: null,
|
||||
context_free: false,
|
||||
elapsed: 0,
|
||||
console: '',
|
||||
account_ram_deltas: [],
|
||||
...override,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,19 @@ const actionEvent: ParserEvent = {
|
||||
kind: 'action',
|
||||
event_id: 'id1',
|
||||
...BLOCK,
|
||||
transaction_id: 'tx0000000000000000000000000000000000000000000000000000000000000000',
|
||||
account: 'eosio',
|
||||
name: 'updateauth',
|
||||
authorization: [],
|
||||
data: { from: 'alice', permission: 'active' },
|
||||
action_ordinal: 1,
|
||||
creator_action_ordinal: 0,
|
||||
global_sequence: 100n,
|
||||
receipt: null,
|
||||
context_free: false,
|
||||
elapsed: 0,
|
||||
console: '',
|
||||
account_ram_deltas: [],
|
||||
}
|
||||
|
||||
const deltaEvent: ParserEvent = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@coopenomics/coopos-ship-reader",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"description": "Clean-room SHiP WebSocket client for EOSIO/Antelope blockchains",
|
||||
"license": "MIT",
|
||||
"author": "Coopenomics contributors",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ABI, Serializer, Bytes } from '@wharfkit/antelope'
|
||||
import { ShipProtocolError } from './errors.js'
|
||||
import type { BlockPosition, ShipBlock, ShipTrace, ShipDelta, ActionReceipt, ActionAuthorization } from './types/ship.js'
|
||||
import type { BlockPosition, ShipBlock, ShipTrace, ShipDelta, ActionReceipt, ActionAuthorization, AuthSequence, AccountRamDelta } from './types/ship.js'
|
||||
|
||||
export type ShipAbi = ABI
|
||||
|
||||
@@ -61,7 +61,12 @@ interface RawActionTrace {
|
||||
}
|
||||
receipt: RawActionReceipt | null
|
||||
action_ordinal: number
|
||||
global_sequence: string
|
||||
creator_action_ordinal?: number
|
||||
global_sequence?: string
|
||||
context_free?: boolean
|
||||
elapsed?: string | number
|
||||
console?: string
|
||||
account_ram_deltas?: Array<{ account: string; delta: string | number }>
|
||||
}
|
||||
|
||||
interface RawActionReceipt {
|
||||
@@ -69,6 +74,9 @@ interface RawActionReceipt {
|
||||
act_digest: string
|
||||
global_sequence: string
|
||||
recv_sequence: string
|
||||
// auth_sequence — массив пар (account, sequence). wharfkit может отдать как
|
||||
// объект {account, sequence} или как кортеж [account, sequence].
|
||||
auth_sequence?: Array<{ account: string; sequence: string | number } | [string, string | number]>
|
||||
code_sequence: number
|
||||
abi_sequence: number
|
||||
}
|
||||
@@ -142,17 +150,28 @@ export function decodeBlocksResult(raw: unknown, abi: ShipAbi, blockNum: number,
|
||||
const receiptData = Array.isArray(at.receipt)
|
||||
? (at.receipt[1] as RawActionTrace['receipt'])
|
||||
: at.receipt
|
||||
const authSequence: AuthSequence[] = (receiptData?.auth_sequence ?? []).map(pair =>
|
||||
Array.isArray(pair)
|
||||
? { account: String(pair[0]), sequence: String(pair[1]) }
|
||||
: { account: String(pair.account), sequence: String(pair.sequence) },
|
||||
)
|
||||
const receipt: ActionReceipt | null = receiptData
|
||||
? ({
|
||||
receiver: String(receiptData.receiver),
|
||||
actDigest: String(receiptData.act_digest),
|
||||
globalSequence: BigInt(receiptData.global_sequence),
|
||||
recvSequence: BigInt(receiptData.recv_sequence),
|
||||
authSequence,
|
||||
codeSequence: receiptData.code_sequence,
|
||||
abiSequence: receiptData.abi_sequence,
|
||||
} as ActionReceipt)
|
||||
: null
|
||||
|
||||
const accountRamDeltas: AccountRamDelta[] = (at.account_ram_deltas ?? []).map(d => ({
|
||||
account: String(d.account),
|
||||
delta: Number(d.delta),
|
||||
}))
|
||||
|
||||
// action_trace_v1 не имеет top-level global_sequence (только в receipt).
|
||||
// Fallback: если at.global_sequence undefined — берём из receipt.
|
||||
const topGlobalSeq = at.global_sequence ?? receiptData?.global_sequence
|
||||
@@ -162,8 +181,13 @@ export function decodeBlocksResult(raw: unknown, abi: ShipAbi, blockNum: number,
|
||||
authorization,
|
||||
actRaw: at.act.data instanceof Bytes ? at.act.data.array : Uint8Array.from([]),
|
||||
actionOrdinal: at.action_ordinal,
|
||||
creatorActionOrdinal: at.creator_action_ordinal ?? 0,
|
||||
globalSequence: topGlobalSeq !== undefined ? BigInt(topGlobalSeq) : 0n,
|
||||
receipt,
|
||||
contextFree: at.context_free ?? false,
|
||||
elapsed: at.elapsed !== undefined ? Number(at.elapsed) : 0,
|
||||
console: at.console ?? '',
|
||||
accountRamDeltas,
|
||||
blockNum: thisBlock.blockNum,
|
||||
blockId: thisBlock.blockId,
|
||||
blockTime,
|
||||
|
||||
@@ -23,6 +23,8 @@ export type {
|
||||
BlockPosition,
|
||||
ActionReceipt,
|
||||
ActionAuthorization,
|
||||
AuthSequence,
|
||||
AccountRamDelta,
|
||||
} from './types/ship.js'
|
||||
|
||||
export type {
|
||||
|
||||
@@ -8,11 +8,22 @@ export interface ActionAuthorization {
|
||||
readonly permission: string
|
||||
}
|
||||
|
||||
export interface AuthSequence {
|
||||
readonly account: string
|
||||
readonly sequence: string
|
||||
}
|
||||
|
||||
export interface AccountRamDelta {
|
||||
readonly account: string
|
||||
readonly delta: number
|
||||
}
|
||||
|
||||
export interface ActionReceipt {
|
||||
readonly receiver: string
|
||||
readonly actDigest: string
|
||||
readonly globalSequence: bigint
|
||||
readonly recvSequence: bigint
|
||||
readonly authSequence: readonly AuthSequence[]
|
||||
readonly codeSequence: number
|
||||
readonly abiSequence: number
|
||||
}
|
||||
@@ -23,8 +34,13 @@ export interface ShipTrace {
|
||||
readonly authorization: readonly ActionAuthorization[]
|
||||
readonly actRaw: Uint8Array
|
||||
readonly actionOrdinal: number
|
||||
readonly creatorActionOrdinal: number
|
||||
readonly globalSequence: bigint
|
||||
readonly receipt: ActionReceipt | null
|
||||
readonly contextFree: boolean
|
||||
readonly elapsed: number
|
||||
readonly console: string
|
||||
readonly accountRamDeltas: readonly AccountRamDelta[]
|
||||
readonly blockNum: number
|
||||
readonly blockId: string
|
||||
readonly blockTime: string
|
||||
|
||||
Reference in New Issue
Block a user