Links: API, Interfaces, Classes, Types
| GASPRemote |
| GASPStorage |
Links: API, Interfaces, Classes, Types
The communications mechanism between a local GASP instance and a foreign GASP instance.
export interface GASPRemote {
getInitialResponse: (request: GASPInitialRequest) => Promise<GASPInitialResponse>;
getInitialReply: (response: GASPInitialResponse) => Promise<GASPInitialReply>;
requestNode: (graphID: string, txid: string, outputIndex: number, metadata: boolean) => Promise<GASPNode>;
submitNode: (node: GASPNode) => Promise<GASPNodeResponse | void>;
}See also: GASPInitialReply, GASPInitialRequest, GASPInitialResponse, GASPNode, GASPNodeResponse
Interface GASPRemote Details
Given an outgoing initial response, obtain the reply from the foreign instance.
getInitialReply: (response: GASPInitialResponse) => Promise<GASPInitialReply>See also: GASPInitialReply, GASPInitialResponse
Given an outgoing initial request, send the request to the foreign instance and obtain their initial response.
getInitialResponse: (request: GASPInitialRequest) => Promise<GASPInitialResponse>See also: GASPInitialRequest, GASPInitialResponse
Given an outgoing txid, outputIndex and optional metadata, request the associated GASP node from the foreign instane.
requestNode: (graphID: string, txid: string, outputIndex: number, metadata: boolean) => Promise<GASPNode>See also: GASPNode
Given an outgoing node, send the node to the foreign instance and determine which additional inputs (if any) they request in response.
submitNode: (node: GASPNode) => Promise<GASPNodeResponse | void>See also: GASPNode, GASPNodeResponse
Links: API, Interfaces, Classes, Types
Facilitates the finding of UTXOs, determination of needed inputs, temporary graph management, and eventual graph finalization.
export interface GASPStorage {
findKnownUTXOs: (since: number) => Promise<Array<{
txid: string;
outputIndex: number;
}>>;
hydrateGASPNode: (graphID: string, txid: string, outputIndex: number, metadata: boolean) => Promise<GASPNode>;
findNeededInputs: (tx: GASPNode) => Promise<GASPNodeResponse | void>;
appendToGraph: (tx: GASPNode, spentBy?: string) => Promise<void>;
validateGraphAnchor: (graphID: string) => Promise<void>;
discardGraph: (graphID: string) => Promise<void>;
finalizeGraph: (graphID: string) => Promise<void>;
}See also: GASPNode, GASPNodeResponse
Interface GASPStorage Details
Appends a new node to a temporary graph.
appendToGraph: (tx: GASPNode, spentBy?: string) => Promise<void>See also: GASPNode
Deletes all data associated with a temporary graph that has failed to sync, if the graph exists.
discardGraph: (graphID: string) => Promise<void>Finalizes a graph, solidifying the new UTXO and its ancestors so that it will appear in the list of known UTXOs.
finalizeGraph: (graphID: string) => Promise<void>Returns an array of transaction outpoints that are currently known to be unspent (given an optional timestamp). Non-confirmed (non-timestamped) outputs should always be returned, regardless of the timestamp.
findKnownUTXOs: (since: number) => Promise<Array<{
txid: string;
outputIndex: number;
}>>For a given node, returns the inputs needed to complete the graph, including whether updated metadata is requested for those inputs.
findNeededInputs: (tx: GASPNode) => Promise<GASPNodeResponse | void>See also: GASPNode, GASPNodeResponse
For a given txid and output index, returns the associated transaction, a merkle proof if the transaction is in a block, and metadata if if requested. If no metadata is requested, metadata hashes on inputs are not returned.
hydrateGASPNode: (graphID: string, txid: string, outputIndex: number, metadata: boolean) => Promise<GASPNode>See also: GASPNode
Checks whether the given graph, in its current state, makes reference only to transactions that are proven in the blockchain, or already known by the recipient to be valid.
validateGraphAnchor: (graphID: string) => Promise<void>Links: API, Interfaces, Classes, Types
| GASP |
| GASPVersionMismatchError |
Links: API, Interfaces, Classes, Types
Main class implementing the Graph Aware Sync Protocol.
export class GASP implements GASPRemote {
version: number;
storage: GASPStorage;
remote: GASPRemote;
lastInteraction: number;
logPrefix: string;
log: boolean;
unidirectional: boolean;
constructor(storage: GASPStorage, remote: GASPRemote, lastInteraction = 0, logPrefix = "[GASP] ", log = false, unidirectional = false)
async sync(): Promise<void>
async buildInitialRequest(since: number): Promise<GASPInitialRequest>
async getInitialResponse(request: GASPInitialRequest): Promise<GASPInitialResponse>
async getInitialReply(response: GASPInitialResponse): Promise<GASPInitialReply>
async requestNode(graphID: string, txid: string, outputIndex: number, metadata: boolean): Promise<GASPNode>
async submitNode(node: GASPNode): Promise<GASPNodeResponse | void>
async completeGraph(graphID: string): Promise<void>
}See also: GASPInitialReply, GASPInitialRequest, GASPInitialResponse, GASPNode, GASPNodeResponse, GASPRemote, GASPStorage
Class GASP Details
constructor(storage: GASPStorage, remote: GASPRemote, lastInteraction = 0, logPrefix = "[GASP] ", log = false, unidirectional = false) See also: GASPRemote, GASPStorage
Argument Details
- storage
- The GASP Storage interface to use
- remote
- The GASP Remote interface to use
- lastInteraction
- The timestamp when we last interacted with this remote party
- logPrefix
- Optional prefix for log messages
- log
- Whether to log messages
- unidirectional
- Whether to disable the "reply" side and do pull-only
Builds the initial request for the sync process.
async buildInitialRequest(since: number): Promise<GASPInitialRequest> See also: GASPInitialRequest
Returns
A promise for the initial request object.
Handles the completion of a newly-synced graph
async completeGraph(graphID: string): Promise<void> Argument Details
- graphID
- The ID of the newly-synced graph
Builds the initial reply based on the received response.
async getInitialReply(response: GASPInitialResponse): Promise<GASPInitialReply> See also: GASPInitialReply, GASPInitialResponse
Returns
A promise for an initial reply
Argument Details
- response
- The initial response object.
Builds the initial response based on the received request.
async getInitialResponse(request: GASPInitialRequest): Promise<GASPInitialResponse> See also: GASPInitialRequest, GASPInitialResponse
Returns
A promise for an initial response
Argument Details
- request
- The initial request object.
Provides a requested node to a foreign instance who requested it.
async requestNode(graphID: string, txid: string, outputIndex: number, metadata: boolean): Promise<GASPNode> See also: GASPNode
Provides a set of inputs we care about after processing a new incoming node. Also finalizes or discards a graph if no additional data is requested from the foreign instance.
async submitNode(node: GASPNode): Promise<GASPNodeResponse | void> See also: GASPNode, GASPNodeResponse
Synchronizes the transaction data between the local and remote participants.
async sync(): Promise<void> Links: API, Interfaces, Classes, Types
export class GASPVersionMismatchError extends Error {
code: "ERR_GASP_VERSION_MISMATCH";
currentVersion: number;
foreignVersion: number;
constructor(message: string, currentVersion: number, foreignVersion: number)
}Links: API, Interfaces, Classes, Types
| GASPInitialReply |
| GASPInitialRequest |
| GASPInitialResponse |
| GASPNode |
| GASPNodeResponse |
Links: API, Interfaces, Classes, Types
Represents the subsequent message sent in reply to the initial response.
export type GASPInitialReply = {
UTXOList: Array<{
txid: string;
outputIndex: number;
}>;
}Links: API, Interfaces, Classes, Types
Represents the initial request made under the Graph Aware Sync Protocol.
export type GASPInitialRequest = {
version: number;
since: number;
}Links: API, Interfaces, Classes, Types
Represents the initial response made under the Graph Aware Sync Protocol.
export type GASPInitialResponse = {
UTXOList: Array<{
txid: string;
outputIndex: number;
}>;
since: number;
}Links: API, Interfaces, Classes, Types
Represents an output, its encompassing transaction, and the associated metadata, together with references to inputs and their metadata.
export type GASPNode = {
graphID: string;
rawTx: string;
outputIndex: number;
proof?: string;
txMetadata?: string;
outputMetadata?: string;
inputs?: Record<string, {
hash: string;
}>;
}Links: API, Interfaces, Classes, Types
Denotes which input transactions are requested, and whether metadata needs to be sent.
export type GASPNodeResponse = {
requestedInputs: Record<string, {
metadata: boolean;
}>;
}Links: API, Interfaces, Classes, Types