Skip to main content

UnifiedSwapStorage<T>

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:43

Unified swap persistence layer for the SDK utilizing an underlying IUnifiedStorage instance with optional in-memory caching via weak refs WeakRef

Type Parameters

Type Parameter
T extends ChainType

Constructors

Constructor

new UnifiedSwapStorage<T>(storage, noWeakRefMap?): UnifiedSwapStorage<T>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:55

Parameters

ParameterTypeDescription
storageIUnifiedStorage<readonly [{ key: "id"; nullable: false; type: "string"; unique: true; }, { key: "escrowHash"; nullable: true; type: "string"; unique: true; }, { key: "type"; nullable: false; type: "number"; unique: false; }, { key: "initiator"; nullable: false; type: "string"; unique: false; }, { key: "state"; nullable: false; type: "number"; unique: false; }, { key: "paymentHash"; nullable: true; type: "string"; unique: false; }], readonly [{ keys: readonly ["initiator", "id"]; unique: false; }, { keys: readonly ["type", "state"]; unique: false; }, { keys: readonly ["type", "paymentHash"]; unique: false; }, { keys: readonly ["type", "initiator", "state"]; unique: false; }]>Underlying storage persistence layer
noWeakRefMap?booleanWhether to disable caching of the swap objects in the weak ref map, this should be set when you need multiple different clients accessing the same swap database (such as when running the SDK in a serverless environment like AWS or Azure)

Returns

UnifiedSwapStorage<T>

Properties

noWeakRefMap?

readonly optional noWeakRefMap: boolean;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:47


storage

readonly storage: IUnifiedStorage<readonly [{
key: "id";
nullable: false;
type: "string";
unique: true;
}, {
key: "escrowHash";
nullable: true;
type: "string";
unique: true;
}, {
key: "type";
nullable: false;
type: "number";
unique: false;
}, {
key: "initiator";
nullable: false;
type: "string";
unique: false;
}, {
key: "state";
nullable: false;
type: "number";
unique: false;
}, {
key: "paymentHash";
nullable: true;
type: "string";
unique: false;
}], readonly [{
keys: readonly ["initiator", "id"];
unique: false;
}, {
keys: readonly ["type", "state"];
unique: false;
}, {
keys: readonly ["type", "paymentHash"];
unique: false;
}, {
keys: readonly ["type", "initiator", "state"];
unique: false;
}]>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:45


weakRefCache

readonly weakRefCache: Map<string, WeakRef<ISwap<T, SwapTypeDefinition<T, ISwapWrapper<T, any, ISwapWrapperOptions>, ISwap<T, any, any>>, number>>>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:46

Methods

init()

init(): Promise<void>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:63

Initializes the underlying storage

Returns

Promise<void>


query()

query<S>(params, reviver): Promise<S[]>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:75

Params are specified in the following way:

  • [[condition1, condition2]] - returns all rows where condition1 AND condition2 is met
  • [[condition1], [condition2]] - returns all rows where condition1 OR condition2 is met
  • [[condition1, condition2], [condition3]] - returns all rows where (condition1 AND condition2) OR condition3 is met

Type Parameters

Type Parameter
S extends ISwap<T, SwapTypeDefinition<T, ISwapWrapper<T, any, ISwapWrapperOptions>, ISwap<T, any, any>>, number>

Parameters

ParameterTypeDescription
paramsQueryParams[][]
reviver(obj) => S

Returns

Promise<S[]>


remove()

remove<S>(value): Promise<void>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:120

Removes a swap from storage

Type Parameters

Type Parameter
S extends ISwap<T, SwapTypeDefinition<T, ISwapWrapper<T, any, ISwapWrapperOptions>, ISwap<T, any, any>>, number>

Parameters

ParameterTypeDescription
valueSSwap to remove

Returns

Promise<void>


removeAll()

removeAll<S>(values): Promise<void>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:129

Removes multiple swaps from storage in a batch operation

Type Parameters

Type Parameter
S extends ISwap<T, SwapTypeDefinition<T, ISwapWrapper<T, any, ISwapWrapperOptions>, ISwap<T, any, any>>, number>

Parameters

ParameterTypeDescription
valuesS[]Array of swaps to remove

Returns

Promise<void>


save()

save<S>(value): Promise<void>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:102

Saves the swap to storage, updating indexes as needed

Type Parameters

Type Parameter
S extends ISwap<T, SwapTypeDefinition<T, ISwapWrapper<T, any, ISwapWrapperOptions>, ISwap<T, any, any>>, number>

Parameters

ParameterTypeDescription
valueSSwap to save

Returns

Promise<void>


saveAll()

saveAll<S>(values): Promise<void>;

Defined in: atomiq-sdk/src/storage/UnifiedSwapStorage.ts:111

Saves multiple swaps to storage in a batch operation

Type Parameters

Type Parameter
S extends ISwap<T, SwapTypeDefinition<T, ISwapWrapper<T, any, ISwapWrapperOptions>, ISwap<T, any, any>>, number>

Parameters

ParameterTypeDescription
valuesS[]Array of swaps to save

Returns

Promise<void>