fix: add support for getConfirmedSignaturesForAddress2 RPC method
This commit is contained in:
@@ -64,6 +64,20 @@ export type ConfirmOptions = {
|
||||
confirmations: ?number,
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for getConfirmedSignaturesForAddress2
|
||||
*
|
||||
* @typedef {Object} ConfirmedSignaturesForAddress2Options
|
||||
* @property {TransactionSignature | undefined} before start searching backwards from this transaction signature.
|
||||
* If not provided the search starts from the highest max confirmed block.
|
||||
* @property {number | undefined} limit maximum transaction signatures to return (between 1 and 1,000, default: 1,000).
|
||||
*
|
||||
*/
|
||||
export type ConfirmedSignaturesForAddress2Options = {
|
||||
before?: TransactionSignature,
|
||||
limit?: number,
|
||||
};
|
||||
|
||||
/**
|
||||
* RPC Response with extra contextual information
|
||||
*
|
||||
@@ -604,12 +618,27 @@ const GetAccountInfoAndContextRpcResult = jsonRpcResultAndContext(
|
||||
);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Expected JSON RPC response for the "getConfirmedSignaturesForAddress" message
|
||||
*/
|
||||
const GetConfirmedSignaturesForAddressRpcResult = jsonRpcResult(
|
||||
struct.array(['string']),
|
||||
);
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getConfirmedSignaturesForAddress2" message
|
||||
*/
|
||||
|
||||
const GetConfirmedSignaturesForAddress2RpcResult = jsonRpcResult(
|
||||
struct.array([
|
||||
struct({
|
||||
signature: 'string',
|
||||
slot: 'number',
|
||||
err: TransactionErrorResult,
|
||||
memo: struct.union(['null', 'string']),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
/***
|
||||
* Expected JSON RPC response for the "accountNotification" message
|
||||
*/
|
||||
@@ -1041,6 +1070,22 @@ export type SignatureStatus = {
|
||||
err: TransactionError | null,
|
||||
};
|
||||
|
||||
/**
|
||||
* A confirmed signature with its status
|
||||
*
|
||||
* @typedef {Object} ConfirmedSignatureInfo
|
||||
* @property {string} signature the transaction signature
|
||||
* @property {number} slot when the transaction was processed
|
||||
* @property {TransactionError | null} err error, if any
|
||||
* @property {string | null} memo memo associated with the transaction, if any
|
||||
*/
|
||||
export type ConfirmedSignatureInfo = {
|
||||
signature: string,
|
||||
slot: number,
|
||||
err: TransactionError | null,
|
||||
memo: string | null,
|
||||
};
|
||||
|
||||
/**
|
||||
* A connection to a fullnode JSON RPC endpoint
|
||||
*/
|
||||
@@ -1836,6 +1881,33 @@ export class Connection {
|
||||
return result.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns confirmed signatures for transactions involving an
|
||||
* address backwards in time from the provided signature or most recent confirmed block
|
||||
*
|
||||
*
|
||||
* @param address queried address
|
||||
* @param options
|
||||
*/
|
||||
async getConfirmedSignaturesForAddress2(
|
||||
address: PublicKey,
|
||||
options: ?ConfirmedSignaturesForAddress2Options,
|
||||
): Promise<Array<ConfirmedSignatureInfo>> {
|
||||
const unsafeRes = await this._rpcRequest(
|
||||
'getConfirmedSignaturesForAddress2',
|
||||
[address.toBase58(), options],
|
||||
);
|
||||
const result = GetConfirmedSignaturesForAddress2RpcResult(unsafeRes);
|
||||
if (result.error) {
|
||||
throw new Error(
|
||||
'failed to get confirmed signatures for address: ' +
|
||||
result.error.message,
|
||||
);
|
||||
}
|
||||
assert(typeof result.result !== 'undefined');
|
||||
return result.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the contents of a Nonce account from the cluster, return with context
|
||||
*/
|
||||
|
Reference in New Issue
Block a user