feat: add support for inner instructions metadata (#13224)
* add-inner-trx * add compiled instructions * remove type parsed inner instruction mistake Co-authored-by: Viacheslav Tsurka <vt@parity.digital>
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							fbc07bf327
						
					
				
				
					commit
					fe8c5b0f0f
				
			@@ -367,11 +367,47 @@ const SimulatedTransactionResponseValidator = jsonRpcResultAndContext(
 | 
			
		||||
  }),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
type PartiallyDecodedInnerInstruction = {
 | 
			
		||||
  index: number,
 | 
			
		||||
  instructions: PartiallyDecodedInstruction[],
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type ParsedInnerInstruction = {
 | 
			
		||||
  index: number,
 | 
			
		||||
  instructions: (ParsedInstruction | PartiallyDecodedInnerInstruction)[],
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Metadata for a parsed confirmed transaction on the ledger
 | 
			
		||||
 *
 | 
			
		||||
 * @typedef {Object} ParsedConfirmedTransactionMeta
 | 
			
		||||
 * @property {number} fee The fee charged for processing the transaction
 | 
			
		||||
 * @property {Array<ParsedInnerInstruction>} innerInstructions An array of cross program invoked parsed instructions
 | 
			
		||||
 * @property {Array<number>} preBalances The balances of the transaction accounts before processing
 | 
			
		||||
 * @property {Array<number>} postBalances The balances of the transaction accounts after processing
 | 
			
		||||
 * @property {Array<string>} logMessages An array of program log messages emitted during a transaction
 | 
			
		||||
 * @property {object|null} err The error result of transaction processing
 | 
			
		||||
 */
 | 
			
		||||
type ParsedConfirmedTransactionMeta = {
 | 
			
		||||
  fee: number,
 | 
			
		||||
  innerInstructions?: ParsedInnerInstruction[],
 | 
			
		||||
  preBalances: Array<number>,
 | 
			
		||||
  postBalances: Array<number>,
 | 
			
		||||
  logMessages?: Array<string>,
 | 
			
		||||
  err: TransactionError | null,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type CompiledInnerInstruction = {
 | 
			
		||||
  index: number,
 | 
			
		||||
  instructions: CompiledInstruction[],
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Metadata for a confirmed transaction on the ledger
 | 
			
		||||
 *
 | 
			
		||||
 * @typedef {Object} ConfirmedTransactionMeta
 | 
			
		||||
 * @property {number} fee The fee charged for processing the transaction
 | 
			
		||||
 * @property {Array<CompiledInnerInstruction>} innerInstructions An array of cross program invoked instructions
 | 
			
		||||
 * @property {Array<number>} preBalances The balances of the transaction accounts before processing
 | 
			
		||||
 * @property {Array<number>} postBalances The balances of the transaction accounts after processing
 | 
			
		||||
 * @property {Array<string>} logMessages An array of program log messages emitted during a transaction
 | 
			
		||||
@@ -379,6 +415,7 @@ const SimulatedTransactionResponseValidator = jsonRpcResultAndContext(
 | 
			
		||||
 */
 | 
			
		||||
type ConfirmedTransactionMeta = {
 | 
			
		||||
  fee: number,
 | 
			
		||||
  innerInstructions?: CompiledInnerInstruction[],
 | 
			
		||||
  preBalances: Array<number>,
 | 
			
		||||
  postBalances: Array<number>,
 | 
			
		||||
  logMessages?: Array<string>,
 | 
			
		||||
@@ -478,7 +515,7 @@ type ParsedTransaction = {
 | 
			
		||||
type ParsedConfirmedTransaction = {
 | 
			
		||||
  slot: number,
 | 
			
		||||
  transaction: ParsedTransaction,
 | 
			
		||||
  meta: ConfirmedTransactionMeta | null,
 | 
			
		||||
  meta: ParsedConfirmedTransactionMeta | null,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -1126,6 +1163,58 @@ const ConfirmedTransactionMetaResult = struct.union([
 | 
			
		||||
  struct.pick({
 | 
			
		||||
    err: TransactionErrorResult,
 | 
			
		||||
    fee: 'number',
 | 
			
		||||
    innerInstructions: struct.union(
 | 
			
		||||
      struct.array([
 | 
			
		||||
        struct({
 | 
			
		||||
          index: 'number',
 | 
			
		||||
          instructions: struct.array([
 | 
			
		||||
            struct({
 | 
			
		||||
              accounts: struct.array(['number']),
 | 
			
		||||
              data: 'string',
 | 
			
		||||
              programIdIndex: 'number',
 | 
			
		||||
            }),
 | 
			
		||||
          ]),
 | 
			
		||||
        }),
 | 
			
		||||
      ]),
 | 
			
		||||
      'null',
 | 
			
		||||
      'undefined',
 | 
			
		||||
    ),
 | 
			
		||||
    preBalances: struct.array(['number']),
 | 
			
		||||
    postBalances: struct.array(['number']),
 | 
			
		||||
    logMessages: struct.union([struct.array(['string']), 'null', 'undefined']),
 | 
			
		||||
  }),
 | 
			
		||||
]);
 | 
			
		||||
/**
 | 
			
		||||
 * @private
 | 
			
		||||
 */
 | 
			
		||||
const ParsedConfirmedTransactionMetaResult = struct.union([
 | 
			
		||||
  'null',
 | 
			
		||||
  struct.pick({
 | 
			
		||||
    err: TransactionErrorResult,
 | 
			
		||||
    fee: 'number',
 | 
			
		||||
    innerInstructions: struct.union(
 | 
			
		||||
      struct.array([
 | 
			
		||||
        struct({
 | 
			
		||||
          index: 'number',
 | 
			
		||||
          instructions: struct.array([
 | 
			
		||||
            struct.union([
 | 
			
		||||
              struct({
 | 
			
		||||
                accounts: struct.array(['string']),
 | 
			
		||||
                data: 'string',
 | 
			
		||||
                programId: 'string',
 | 
			
		||||
              }),
 | 
			
		||||
              struct({
 | 
			
		||||
                parsed: 'any',
 | 
			
		||||
                program: 'string',
 | 
			
		||||
                programId: 'string',
 | 
			
		||||
              }),
 | 
			
		||||
            ]),
 | 
			
		||||
          ]),
 | 
			
		||||
        }),
 | 
			
		||||
      ]),
 | 
			
		||||
      'null',
 | 
			
		||||
      'undefined',
 | 
			
		||||
    ),
 | 
			
		||||
    preBalances: struct.array(['number']),
 | 
			
		||||
    postBalances: struct.array(['number']),
 | 
			
		||||
    logMessages: struct.union([struct.array(['string']), 'null', 'undefined']),
 | 
			
		||||
@@ -1186,7 +1275,7 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(
 | 
			
		||||
    struct.pick({
 | 
			
		||||
      slot: 'number',
 | 
			
		||||
      transaction: ParsedConfirmedTransactionResult,
 | 
			
		||||
      meta: ConfirmedTransactionMetaResult,
 | 
			
		||||
      meta: ParsedConfirmedTransactionMetaResult,
 | 
			
		||||
    }),
 | 
			
		||||
  ]),
 | 
			
		||||
);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user