Skip to main content

UnifiedSwapStorage<T>

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

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:57

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:49


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:47


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:48

Methods​

init()​

init(): Promise<void>;

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

Initializes the underlying storage

Returns​

Promise<void>


query()​

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

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

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:142

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, lenient?): Promise<void>;

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

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
lenient?booleanIn lenient mode the underlying persistent layer doesn't throw on individual swap failures due to optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap isn't mission-critical for executing next steps (e.g. in tick or sync loops)

Returns​

Promise<void>


save()​

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

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

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, lenient?): Promise<void>;

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

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
lenient?booleanIn lenient mode the underlying persistent layer doesn't throw on individual swap failures due to optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap isn't mission-critical for executing next steps (e.g. in tick or sync loops)

Returns​

Promise<void>