• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hirosystems / stacks-blockchain-api / 4756819452

pending completion
4756819452

push

github

GitHub
Merge pull request #1624 from hirosystems/develop

2077 of 3233 branches covered (64.24%)

139 of 293 new or added lines in 24 files covered. (47.44%)

348 existing lines in 8 files now uncovered.

7306 of 9664 relevant lines covered (75.6%)

1757.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/event-stream/core-node-message.ts
1
import { DecodedTxResult } from 'stacks-encoding-native-js';
2
import { ClarityAbi } from './contract-abi';
3

4
export enum CoreNodeEventType {
40✔
5
  ContractEvent = 'contract_event',
40✔
6
  StxTransferEvent = 'stx_transfer_event',
40✔
7
  StxMintEvent = 'stx_mint_event',
40✔
8
  StxBurnEvent = 'stx_burn_event',
40✔
9
  StxLockEvent = 'stx_lock_event',
40✔
10
  NftTransferEvent = 'nft_transfer_event',
40✔
11
  NftMintEvent = 'nft_mint_event',
40✔
12
  NftBurnEvent = 'nft_burn_event',
40✔
13
  FtTransferEvent = 'ft_transfer_event',
40✔
14
  FtMintEvent = 'ft_mint_event',
40✔
15
  FtBurnEvent = 'ft_burn_event',
40✔
16
}
17

18
// TODO: core-node should use a better encoding for this structure;
19
type NonStandardClarityValue = unknown;
20

21
interface CoreNodeEventBase {
22
  /** 0x-prefix transaction hash. */
23
  txid: string;
24
  event_index: number;
25
  committed: boolean;
26
}
27

28
export interface SmartContractEvent extends CoreNodeEventBase {
29
  type: CoreNodeEventType.ContractEvent;
30
  contract_event: {
31
    /** Fully qualified contract ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.kv-store" */
32
    contract_identifier: string;
33
    topic: string;
34
    value: NonStandardClarityValue;
35
    /** Hex encoded Clarity value. */
36
    raw_value: string;
37
  };
38
}
39

40
export interface StxTransferEvent extends CoreNodeEventBase {
41
  type: CoreNodeEventType.StxTransferEvent;
42
  stx_transfer_event: {
43
    recipient: string;
44
    sender: string;
45
    amount: string;
46
    /** Hex-encoded string. Only provided when a memo was specified in the Clarity `stx-transfer?` function (requires a Stacks 2.1 contract). */
47
    memo?: string;
48
  };
49
}
50

51
export interface StxMintEvent extends CoreNodeEventBase {
52
  type: CoreNodeEventType.StxMintEvent;
53
  stx_mint_event: {
54
    recipient: string;
55
    amount: string;
56
  };
57
}
58

59
interface StxBurnEvent extends CoreNodeEventBase {
60
  type: CoreNodeEventType.StxBurnEvent;
61
  stx_burn_event: {
62
    sender: string;
63
    amount: string;
64
  };
65
}
66

67
export interface StxLockEvent extends CoreNodeEventBase {
68
  type: CoreNodeEventType.StxLockEvent;
69
  /** TODO: what dis? */
70
  committed: boolean;
71
  stx_lock_event: {
72
    /** String quoted base10 integer. */
73
    locked_amount: string;
74
    /** String quoted base10 integer. */
75
    unlock_height: string;
76
    /** STX principal associated with the locked tokens. */
77
    locked_address: string;
78
    /** Fully qualified contract ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.pox" or "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.pox-2" */
79
    contract_identifier?: string;
80
  };
81
}
82

83
export interface NftTransferEvent extends CoreNodeEventBase {
84
  type: CoreNodeEventType.NftTransferEvent;
85
  nft_transfer_event: {
86
    /** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
87
    asset_identifier: string;
88
    recipient: string;
89
    sender: string;
90
    value: NonStandardClarityValue;
91
    /** Hex encoded Clarity value. */
92
    raw_value: string;
93
  };
94
}
95

96
export interface NftMintEvent extends CoreNodeEventBase {
97
  type: CoreNodeEventType.NftMintEvent;
98
  nft_mint_event: {
99
    /** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
100
    asset_identifier: string;
101
    recipient: string;
102
    value: NonStandardClarityValue;
103
    /** Hex encoded Clarity value. */
104
    raw_value: string;
105
  };
106
}
107

108
interface NftBurnEvent extends CoreNodeEventBase {
109
  type: CoreNodeEventType.NftBurnEvent;
110
  nft_burn_event: {
111
    /** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
112
    asset_identifier: string;
113
    sender: string;
114
    value: NonStandardClarityValue;
115
    /** Hex encoded Clarity value. */
116
    raw_value: string;
117
  };
118
}
119

120
interface FtTransferEvent extends CoreNodeEventBase {
121
  type: CoreNodeEventType.FtTransferEvent;
122
  ft_transfer_event: {
123
    /** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
124
    asset_identifier: string;
125
    recipient: string;
126
    sender: string;
127
    amount: string;
128
  };
129
}
130

131
export interface FtMintEvent extends CoreNodeEventBase {
132
  type: CoreNodeEventType.FtMintEvent;
133
  ft_mint_event: {
134
    /** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
135
    asset_identifier: string;
136
    recipient: string;
137
    amount: string;
138
  };
139
}
140

141
interface FtBurnEvent extends CoreNodeEventBase {
142
  type: CoreNodeEventType.FtBurnEvent;
143
  ft_burn_event: {
144
    /** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
145
    asset_identifier: string;
146
    sender: string;
147
    amount: string;
148
  };
149
}
150

151
interface BurnchainOpRegisterAssetNft {
152
  register_asset: {
153
    asset_type: 'nft';
154
    burn_header_hash: string;
155
    l1_contract_id: string;
156
    l2_contract_id: string;
157
    txid: string;
158
  };
159
}
160

161
interface BurnchainOpRegisterAssetFt {
162
  register_asset: {
163
    asset_type: 'ft';
164
    burn_header_hash: string;
165
    l1_contract_id: string;
166
    l2_contract_id: string;
167
    txid: string;
168
  };
169
}
170

171
export type BurnchainOp = BurnchainOpRegisterAssetNft | BurnchainOpRegisterAssetFt;
172

173
export type CoreNodeEvent =
174
  | SmartContractEvent
175
  | StxTransferEvent
176
  | StxMintEvent
177
  | StxBurnEvent
178
  | StxLockEvent
179
  | FtTransferEvent
180
  | FtMintEvent
181
  | FtBurnEvent
182
  | NftTransferEvent
183
  | NftMintEvent
184
  | NftBurnEvent;
185

186
export type CoreNodeTxStatus = 'success' | 'abort_by_response' | 'abort_by_post_condition';
187

188
export interface CoreNodeTxMessage {
189
  raw_tx: string;
190
  status: CoreNodeTxStatus;
191
  raw_result: string;
192
  txid: string;
193
  tx_index: number;
194
  contract_abi: ClarityAbi | null;
195
  execution_cost: CoreNodeExecutionCostMessage;
196
  microblock_sequence: number | null;
197
  microblock_hash: string | null;
198
  microblock_parent_hash: string | null;
199
  burnchain_op?: BurnchainOp | null;
200
}
201

202
export interface CoreNodeMicroblockTxMessage extends CoreNodeTxMessage {
203
  microblock_sequence: number;
204
  microblock_hash: string;
205
  microblock_parent_hash: string;
206
}
207

208
export function isTxWithMicroblockInfo(tx: CoreNodeTxMessage): tx is CoreNodeMicroblockTxMessage {
40✔
209
  if (tx.microblock_hash && tx.microblock_parent_hash && tx.microblock_sequence !== null) {
982✔
210
    return true;
86✔
211
  }
212
  if (tx.microblock_hash || tx.microblock_parent_hash || tx.microblock_sequence !== null) {
896!
UNCOV
213
    throw new Error(
×
214
      `Unexpected transaction object that contains only partial microblock data: ${JSON.stringify(
215
        tx
216
      )}`
217
    );
218
  }
219
  return false;
896✔
220
}
221

222
export interface CoreNodeBlockMessage {
223
  block_hash: string;
224
  block_height: number;
225
  burn_block_time: number;
226
  burn_block_hash: string;
227
  burn_block_height: number;
228
  miner_txid: string;
229
  index_block_hash: string;
230
  parent_index_block_hash: string;
231
  parent_block_hash: string;
232
  parent_microblock: string;
233
  parent_microblock_sequence: number;
234
  parent_burn_block_hash: string;
235
  parent_burn_block_height: number;
236
  parent_burn_block_timestamp: number;
237
  events: CoreNodeEvent[];
238
  transactions: CoreNodeTxMessage[];
239
  matured_miner_rewards: {
240
    from_index_consensus_hash: string;
241
    from_stacks_block_hash: string;
242
    /** STX principal */
243
    recipient: string;
244
    /** STX principal (available starting in Stacks 2.1) */
245
    miner_address: string | null;
246
    /** String quoted micro-STX amount. */
247
    coinbase_amount: string;
248
    /** String quoted micro-STX amount. */
249
    tx_fees_anchored: string;
250
    /** String quoted micro-STX amount. */
251
    tx_fees_streamed_confirmed: string;
252
    /** String quoted micro-STX amount. */
253
    tx_fees_streamed_produced: string;
254
  }[];
255
  pox_v1_unlock_height?: number;
256
}
257

258
export interface CoreNodeParsedTxMessage {
259
  core_tx: CoreNodeTxMessage;
260
  parsed_tx: DecodedTxResult;
261
  raw_tx: string;
262
  nonce: number;
263
  sender_address: string;
264
  sponsor_address: string | undefined;
265
  block_hash: string;
266
  index_block_hash: string;
267
  parent_index_block_hash: string;
268
  parent_block_hash: string;
269
  microblock_sequence: number;
270
  microblock_hash: string;
271
  block_height: number;
272
  burn_block_time: number;
273
  parent_burn_block_time: number;
274
  parent_burn_block_hash: string;
275
}
276

277
export interface CoreNodeBurnBlockMessage {
278
  burn_block_hash: string;
279
  burn_block_height: number;
280
  /** Amount in BTC satoshis. */
281
  burn_amount: number;
282
  reward_recipients: [
283
    {
284
      /** Bitcoin address (b58 encoded). */
285
      recipient: string;
286
      /** Amount in BTC satoshis. */
287
      amt: number;
288
    }
289
  ];
290
  /**
291
   * Array of the Bitcoin addresses that would validly receive PoX commitments during this block.
292
   * These addresses may not actually receive rewards during this block if the block is faster
293
   * than miners have an opportunity to commit.
294
   */
295
  reward_slot_holders: string[];
296
}
297

298
export type CoreNodeDropMempoolTxReasonType =
299
  | 'ReplaceByFee'
300
  | 'ReplaceAcrossFork'
301
  | 'TooExpensive'
302
  | 'StaleGarbageCollect';
303

304
export interface CoreNodeDropMempoolTxMessage {
305
  dropped_txids: string[];
306
  reason: CoreNodeDropMempoolTxReasonType;
307
}
308

309
export interface CoreNodeAttachmentMessage {
310
  attachment_index: number;
311
  index_block_hash: string;
312
  block_height: string; // string quoted integer?
313
  content_hash: string;
314
  contract_id: string;
315
  /** Hex serialized Clarity value */
316
  metadata: string;
317
  tx_id: string;
318
  /* Hex encoded attachment content bytes */
319
  content: string;
320
}
321

322
interface CoreNodeExecutionCostMessage {
323
  read_count: number;
324
  read_length: number;
325
  runtime: number;
326
  write_count: number;
327
  write_length: number;
328
}
329

330
export interface CoreNodeMicroblockMessage {
331
  parent_index_block_hash: string;
332
  burn_block_hash: string;
333
  burn_block_height: number;
334
  burn_block_timestamp: number;
335
  // TODO(mb): assume this is too hard to get from the stacks-node event
336
  // parent_block_hash: string;
337
  transactions: CoreNodeMicroblockTxMessage[];
338
  events: CoreNodeEvent[];
339
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc