Skip to content

Commit c6af33b

Browse files
authored
Mempool/decoded opnet tx (#236)
2 parents e4e5927 + 6d1d20e commit c6af33b

98 files changed

Lines changed: 745 additions & 429 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docker/config/btc.conf.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ UTXO_SAVE_INTERVAL = 120000 # Save UTXOs interval in milliseconds
6060
[OP_NET]
6161
MODE = "ARCHIVE" # ARCHIVE, FULL, SNAP, LIGHT. Only ARCHIVE is supported at this time
6262

63-
ENABLED_AT_BLOCK = 0 # Block height at which the OP_NET should be enabled
6463
REINDEX = false # Set to true to reindex the OP_NET
6564
REINDEX_FROM_BLOCK = 0 # Block height from which to reindex the OP_NET
6665

src/components/openapi.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ info:
44
title: OpNet RPC API
55
description: This document is the official API documentation of OpNet JSON-RPC.
66
version: 1.0.0
7-
pointerResolutionBasePath: "/"
7+
pointerResolutionBasePath: '/'
88
swagger: 2.0
9-
basePath: "/"
9+
basePath: '/'
1010
tags:
11-
- name: "Websocket"
12-
description: "OpNet websocket configuration related endpoints."
11+
- name: 'Websocket'
12+
description: 'OpNet websocket configuration related endpoints.'
1313
components:
1414
securitySchemes:
1515
BearerAuth:

src/components/schemas/_index.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ components:
4848
address:
4949
type: string
5050
description: An address or public key hash.
51-
example: "0222513da2b72f9f8e26a016087ee191fc60be4671cae286bd2f16261c026dcb12"
51+
example: '0222513da2b72f9f8e26a016087ee191fc60be4671cae286bd2f16261c026dcb12'
5252
required: true
5353
InteractionTransaction:
5454
allOf:
@@ -181,7 +181,7 @@ components:
181181
data:
182182
type: string
183183
description: The transaction to broadcast.
184-
example: "02000000000101"
184+
example: '02000000000101'
185185
required: true
186186
psbt:
187187
type: boolean
@@ -200,6 +200,6 @@ components:
200200
amount:
201201
type: number
202202
description: The amount to wrap in satoshis
203-
example: "0"
203+
example: '0'
204204
default: 1000
205205
required: true

src/config/btc.sample.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ MODE = "ARCHIVE" # ARCHIVE, FULL, LIGHT. Only ARCHIVE is supported at this time
4444
# LIGHT NODES HAVE A LIMITED VIEW OF THE BLOCKCHAIN, they ONLY index 10k blocks from the latest block
4545
LIGHT_MODE_FROM_BLOCK = 10000 # Number of blocks to index in light mode
4646

47-
ENABLED_AT_BLOCK = 0 # Block height at which the OP_NET should be enabled
4847
REINDEX = true # Set to true to reindex the OP_NET
4948
REINDEX_FROM_BLOCK = 800000 # Block height from which to reindex the OP_NET
5049

src/protocols/OPNetAPIProtocol.proto

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,12 @@ message PendingTransactionResponse {
701701
string firstSeen = 2;
702702
// Block height at which the transaction was observed (0x-prefixed hex).
703703
string blockHeight = 3;
704-
// Theoretical gas limit for OPNet execution (0x-prefixed hex).
705-
string theoreticalGasLimit = 4;
706-
// Priority fee attached to the transaction (0x-prefixed hex).
707-
string priorityFee = 5;
708-
// Whether this transaction targets an OPNet contract.
709-
bool isOPNet = 6;
704+
// Theoretical gas limit for OPNet execution (0x-prefixed hex). Present only for OPNet transactions.
705+
optional string theoreticalGasLimit = 4;
706+
// Priority fee attached to the transaction (0x-prefixed hex). Present only for OPNet transactions.
707+
optional string priorityFee = 5;
708+
// The OPNet transaction type (Generic, Interaction, Deployment).
709+
string transactionType = 6;
710710
// Whether the transaction was submitted as a PSBT.
711711
bool psbt = 7;
712712
// The transaction inputs.
@@ -715,6 +715,14 @@ message PendingTransactionResponse {
715715
repeated MempoolTransactionOutput outputs = 9;
716716
// The full raw transaction as a hex string.
717717
string raw = 10;
718+
// The sender address (p2tr format). Present only for OPNet transactions.
719+
optional string from = 11;
720+
// The target contract address (p2op format). Present only for OPNet transactions.
721+
optional string contractAddress = 12;
722+
// Hex-encoded calldata. Present only for OPNet transactions.
723+
optional string calldata = 13;
724+
// Hex-encoded bytecode. Present only for deployment transactions.
725+
optional string bytecode = 14;
718726
}
719727

720728
// Request: fetch the latest pending transactions with optional address filter.
@@ -755,8 +763,8 @@ message NewMempoolTransactionNotification {
755763
uint32 subscriptionId = 1;
756764
// The txid of the new mempool transaction.
757765
string txId = 2;
758-
// Whether this transaction targets an OPNet contract.
759-
bool isOPNet = 3;
766+
// The OPNet transaction type (Generic, Interaction, Deployment).
767+
string transactionType = 3;
760768
// Unix timestamp in milliseconds when the transaction was observed.
761769
uint64 timestamp = 4;
762770
}

src/src/api/data-converter/TransactionConverterForAPI.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DataConverter } from '@btc-vision/bsi-common';
2-
import { toBase64, toHex } from '@btc-vision/bitcoin';
2+
import { toHex } from '@btc-vision/bitcoin';
33
import { Binary } from 'mongodb';
44
import { OPNetTransactionTypes } from '../../blockchain-indexer/processor/transaction/enums/OPNetTransactionTypes.js';
55
import {
@@ -40,18 +40,35 @@ export class TransactionConverterForAPI {
4040
) satisfies EventReceiptDataForAPI[])
4141
: [];
4242

43+
const hash: string =
44+
transaction.hash instanceof Uint8Array
45+
? toHex(transaction.hash)
46+
: (transaction.hash as Binary).toString('hex');
47+
48+
const id: string =
49+
transaction.id instanceof Uint8Array
50+
? toHex(transaction.id)
51+
: (transaction.id as Binary).toString('hex');
52+
4353
const newTx: TransactionDocumentForAPI<OPNetTransactionTypes> = {
4454
...transaction,
45-
hash: toHex(transaction.hash),
46-
id: toHex(transaction.id),
55+
hash: hash,
56+
id: id,
4757
blockNumber:
4858
'0x' + DataConverter.fromDecimal128(transaction.blockHeight || 0n).toString(16),
4959
inputs: transaction.inputs?.map((input) => {
60+
let originalTransactionId: string | undefined;
61+
62+
if (input.originalTransactionId) {
63+
originalTransactionId =
64+
input.originalTransactionId instanceof Uint8Array
65+
? toHex(input.originalTransactionId)
66+
: (input.originalTransactionId as Binary).toString('hex');
67+
}
68+
5069
return {
5170
...input,
52-
originalTransactionId: input.originalTransactionId
53-
? toHex(input.originalTransactionId)
54-
: undefined,
71+
originalTransactionId: originalTransactionId,
5572
scriptSignature: input.scriptSignature,
5673
};
5774
}),

src/src/api/json-rpc/types/interfaces/params/blocks/BlockByChecksumParams.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { JSONRpcMethods } from '../../../enums/JSONRpcMethods.js';
22
import { JSONRpcParams } from '../../JSONRpcParams.js';
33

4-
export interface BlockByChecksumAsObject
5-
extends JSONRpcParams<JSONRpcMethods.GET_BLOCK_BY_CHECKSUM> {
4+
export interface BlockByChecksumAsObject extends JSONRpcParams<JSONRpcMethods.GET_BLOCK_BY_CHECKSUM> {
65
readonly blockHash: string;
76
readonly sendTransactions?: boolean;
87
}

src/src/api/json-rpc/types/interfaces/params/epochs/EpochByNumberParams.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { JSONRpcMethods } from '../../../enums/JSONRpcMethods.js';
22
import { JSONRpcParams } from '../../JSONRpcParams.js';
33

4-
export interface EpochByNumberParamsAsObject
5-
extends JSONRpcParams<JSONRpcMethods.GET_EPOCH_BY_NUMBER> {
4+
export interface EpochByNumberParamsAsObject extends JSONRpcParams<JSONRpcMethods.GET_EPOCH_BY_NUMBER> {
65
readonly height: bigint | -1 | string;
76
readonly includeSubmissions?: boolean;
87
}

src/src/api/json-rpc/types/interfaces/params/epochs/GetEpochTemplateParams.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { JSONRpcMethods } from '../../../enums/JSONRpcMethods.js';
22
import { JSONRpcParams } from '../../JSONRpcParams.js';
33

4-
export interface EpochTemplateParamsAsObject
5-
extends JSONRpcParams<JSONRpcMethods.GET_EPOCH_TEMPLATE> {}
4+
export interface EpochTemplateParamsAsObject extends JSONRpcParams<JSONRpcMethods.GET_EPOCH_TEMPLATE> {}
65

76
export type EpochTemplateAsArray = [EpochTemplateParamsAsObject];
87

src/src/api/json-rpc/types/interfaces/params/mempool/GetLatestPendingTransactionsParams.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { JSONRpcMethods } from '../../../enums/JSONRpcMethods.js';
22
import { JSONRpcParams } from '../../JSONRpcParams.js';
33

44
/** Object-form parameters for {@link JSONRpcMethods.GET_LATEST_PENDING_TRANSACTIONS}. */
5-
export interface GetLatestPendingTransactionsParamsAsObject
6-
extends JSONRpcParams<JSONRpcMethods.GET_LATEST_PENDING_TRANSACTIONS> {
5+
export interface GetLatestPendingTransactionsParamsAsObject extends JSONRpcParams<JSONRpcMethods.GET_LATEST_PENDING_TRANSACTIONS> {
76
/** A single address to auto-resolve into all derived wallet address types. */
87
readonly address?: string;
98
/** Explicit list of addresses to filter mempool transactions by. */

0 commit comments

Comments
 (0)