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

hirosystems / stacks-blockchain-api / 3885427095

pending completion
3885427095

push

github

Matthew Little
chore!: support for Stacks 2.1

2029 of 3104 branches covered (65.37%)

7123 of 9267 relevant lines covered (76.86%)

1177.49 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 {
39✔
5
  ContractEvent = 'contract_event',
39✔
6
  StxTransferEvent = 'stx_transfer_event',
39✔
7
  StxMintEvent = 'stx_mint_event',
39✔
8
  StxBurnEvent = 'stx_burn_event',
39✔
9
  StxLockEvent = 'stx_lock_event',
39✔
10
  NftTransferEvent = 'nft_transfer_event',
39✔
11
  NftMintEvent = 'nft_mint_event',
39✔
12
  NftBurnEvent = 'nft_burn_event',
39✔
13
  FtTransferEvent = 'ft_transfer_event',
39✔
14
  FtMintEvent = 'ft_mint_event',
39✔
15
  FtBurnEvent = 'ft_burn_event',
39✔
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
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
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
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
export type CoreNodeEvent =
152
  | SmartContractEvent
153
  | StxTransferEvent
154
  | StxMintEvent
155
  | StxBurnEvent
156
  | StxLockEvent
157
  | FtTransferEvent
158
  | FtMintEvent
159
  | FtBurnEvent
160
  | NftTransferEvent
161
  | NftMintEvent
162
  | NftBurnEvent;
163

164
export type CoreNodeTxStatus = 'success' | 'abort_by_response' | 'abort_by_post_condition';
165

166
export interface CoreNodeTxMessage {
167
  raw_tx: string;
168
  status: CoreNodeTxStatus;
169
  raw_result: string;
170
  txid: string;
171
  tx_index: number;
172
  contract_abi: ClarityAbi | null;
173
  execution_cost: CoreNodeExecutionCostMessage;
174
  microblock_sequence: number | null;
175
  microblock_hash: string | null;
176
  microblock_parent_hash: string | null;
177
}
178

179
export interface CoreNodeMicroblockTxMessage extends CoreNodeTxMessage {
180
  microblock_sequence: number;
181
  microblock_hash: string;
182
  microblock_parent_hash: string;
183
}
184

185
export function isTxWithMicroblockInfo(tx: CoreNodeTxMessage): tx is CoreNodeMicroblockTxMessage {
39✔
186
  if (tx.microblock_hash && tx.microblock_parent_hash && tx.microblock_sequence !== null) {
726✔
187
    return true;
72✔
188
  }
189
  if (tx.microblock_hash || tx.microblock_parent_hash || tx.microblock_sequence !== null) {
654!
190
    throw new Error(
×
191
      `Unexpected transaction object that contains only partial microblock data: ${JSON.stringify(
192
        tx
193
      )}`
194
    );
195
  }
196
  return false;
654✔
197
}
198

199
export interface CoreNodeBlockMessage {
200
  block_hash: string;
201
  block_height: number;
202
  burn_block_time: number;
203
  burn_block_hash: string;
204
  burn_block_height: number;
205
  miner_txid: string;
206
  index_block_hash: string;
207
  parent_index_block_hash: string;
208
  parent_block_hash: string;
209
  parent_microblock: string;
210
  parent_microblock_sequence: number;
211
  parent_burn_block_hash: string;
212
  parent_burn_block_height: number;
213
  parent_burn_block_timestamp: number;
214
  events: CoreNodeEvent[];
215
  transactions: CoreNodeTxMessage[];
216
  matured_miner_rewards: {
217
    from_index_consensus_hash: string;
218
    from_stacks_block_hash: string;
219
    /** STX principal */
220
    recipient: string;
221
    /** STX principal (available starting in Stacks 2.1) */
222
    miner_address: string | null;
223
    /** String quoted micro-STX amount. */
224
    coinbase_amount: string;
225
    /** String quoted micro-STX amount. */
226
    tx_fees_anchored: string;
227
    /** String quoted micro-STX amount. */
228
    tx_fees_streamed_confirmed: string;
229
    /** String quoted micro-STX amount. */
230
    tx_fees_streamed_produced: string;
231
  }[];
232
  pox_v1_unlock_height?: number;
233
}
234

235
export interface CoreNodeParsedTxMessage {
236
  core_tx: CoreNodeTxMessage;
237
  parsed_tx: DecodedTxResult;
238
  raw_tx: string;
239
  nonce: number;
240
  sender_address: string;
241
  sponsor_address: string | undefined;
242
  block_hash: string;
243
  index_block_hash: string;
244
  parent_index_block_hash: string;
245
  parent_block_hash: string;
246
  microblock_sequence: number;
247
  microblock_hash: string;
248
  block_height: number;
249
  burn_block_time: number;
250
  parent_burn_block_time: number;
251
  parent_burn_block_hash: string;
252
}
253

254
export interface CoreNodeBurnBlockMessage {
255
  burn_block_hash: string;
256
  burn_block_height: number;
257
  /** Amount in BTC satoshis. */
258
  burn_amount: number;
259
  reward_recipients: [
260
    {
261
      /** Bitcoin address (b58 encoded). */
262
      recipient: string;
263
      /** Amount in BTC satoshis. */
264
      amt: number;
265
    }
266
  ];
267
  /**
268
   * Array of the Bitcoin addresses that would validly receive PoX commitments during this block.
269
   * These addresses may not actually receive rewards during this block if the block is faster
270
   * than miners have an opportunity to commit.
271
   */
272
  reward_slot_holders: string[];
273
}
274

275
export type CoreNodeDropMempoolTxReasonType =
276
  | 'ReplaceByFee'
277
  | 'ReplaceAcrossFork'
278
  | 'TooExpensive'
279
  | 'StaleGarbageCollect';
280

281
export interface CoreNodeDropMempoolTxMessage {
282
  dropped_txids: string[];
283
  reason: CoreNodeDropMempoolTxReasonType;
284
}
285

286
export interface CoreNodeAttachmentMessage {
287
  attachment_index: number;
288
  index_block_hash: string;
289
  block_height: string; // string quoted integer?
290
  content_hash: string;
291
  contract_id: string;
292
  /** Hex serialized Clarity value */
293
  metadata: string;
294
  tx_id: string;
295
  /* Hex encoded attachment content bytes */
296
  content: string;
297
}
298

299
interface CoreNodeExecutionCostMessage {
300
  read_count: number;
301
  read_length: number;
302
  runtime: number;
303
  write_count: number;
304
  write_length: number;
305
}
306

307
export interface CoreNodeMicroblockMessage {
308
  parent_index_block_hash: string;
309
  burn_block_hash: string;
310
  burn_block_height: number;
311
  burn_block_timestamp: number;
312
  // TODO(mb): assume this is too hard to get from the stacks-node event
313
  // parent_block_hash: string;
314
  transactions: CoreNodeMicroblockTxMessage[];
315
  events: CoreNodeEvent[];
316
}
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