@splashprotocol/remote-builder 2.0.0-beta.6
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +62 -0
- package/dist/index.cjs +94 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +65 -0
- package/package.json +39 -0
- package/src/builders/SplashRemoteBuilder.ts +41 -0
- package/src/core/models/RemoteTransaction/RemoteTransaction.spec.ts +25 -0
- package/src/core/models/RemoteTransaction/RemoteTransaction.ts +40 -0
- package/src/core/models/SignedRemoteTransaction/SignedRemoteTransaction.spec.ts +21 -0
- package/src/core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts +32 -0
- package/src/core/types/RemoteBuilder.ts +16 -0
- package/src/index.ts +4 -0
- package/src/mocks/BackendEmulator.ts +10 -0
- package/src/mocks/RemoteBuilderEmulator.ts +26 -0
- package/tsconfig.json +7 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
[2K[1G[1myarn run v1.22.22[22m
|
3
|
+
[2K[1G[33mwarning[39m package.json: No license field
|
4
|
+
[2K[1G[2m$ tsup src/index.ts --format esm,cjs --dts --clean[22m
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
7
|
+
[34mCLI[39m tsup v8.3.0
|
8
|
+
[34mCLI[39m Target: esnext
|
9
|
+
[34mCLI[39m Cleaning output folder
|
10
|
+
[34mESM[39m Build start
|
11
|
+
[34mCJS[39m Build start
|
12
|
+
|
13
|
+
[90m[[90m4:36:02 PM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
14
|
+
|
15
|
+
package.json:16:6:
|
16
|
+
[37m 16 │ [32m"types"[37m: "./dist/index.d.ts"
|
17
|
+
╵ [32m~~~~~~~[0m
|
18
|
+
|
19
|
+
The "import" condition comes earlier and will be used for all "import" statements:
|
20
|
+
|
21
|
+
package.json:15:6:
|
22
|
+
[37m 15 │ [32m"import"[37m: "./dist/index.js",
|
23
|
+
╵ [32m~~~~~~~~[0m
|
24
|
+
|
25
|
+
The "require" condition comes earlier and will be used for all "require" calls:
|
26
|
+
|
27
|
+
package.json:14:6:
|
28
|
+
[37m 14 │ [32m"require"[37m: "./dist/index.cjs",
|
29
|
+
╵ [32m~~~~~~~~~[0m
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
[90m[[90m4:36:02 PM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
35
|
+
|
36
|
+
package.json:16:6:
|
37
|
+
[37m 16 │ [32m"types"[37m: "./dist/index.d.ts"
|
38
|
+
╵ [32m~~~~~~~[0m
|
39
|
+
|
40
|
+
The "import" condition comes earlier and will be used for all "import" statements:
|
41
|
+
|
42
|
+
package.json:15:6:
|
43
|
+
[37m 15 │ [32m"import"[37m: "./dist/index.js",
|
44
|
+
╵ [32m~~~~~~~~[0m
|
45
|
+
|
46
|
+
The "require" condition comes earlier and will be used for all "require" calls:
|
47
|
+
|
48
|
+
package.json:14:6:
|
49
|
+
[37m 14 │ [32m"require"[37m: "./dist/index.cjs",
|
50
|
+
╵ [32m~~~~~~~~~[0m
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m2.58 KB[39m
|
55
|
+
[32mCJS[39m ⚡️ Build success in 29ms
|
56
|
+
[32mESM[39m [1mdist/index.js [22m[32m1.47 KB[39m
|
57
|
+
[32mESM[39m ⚡️ Build success in 29ms
|
58
|
+
[34mDTS[39m Build start
|
59
|
+
[32mDTS[39m ⚡️ Build success in 830ms
|
60
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.87 KB[39m
|
61
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m1.87 KB[39m
|
62
|
+
[2K[1G✨ Done in 1.71s.
|
package/dist/index.cjs
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/index.ts
|
21
|
+
var src_exports = {};
|
22
|
+
__export(src_exports, {
|
23
|
+
RemoteTransaction: () => RemoteTransaction,
|
24
|
+
SignedRemoteTransaction: () => SignedRemoteTransaction,
|
25
|
+
SplashRemoteBuilder: () => SplashRemoteBuilder
|
26
|
+
});
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
28
|
+
|
29
|
+
// src/core/models/RemoteTransaction/RemoteTransaction.ts
|
30
|
+
var RemoteTransaction = class _RemoteTransaction {
|
31
|
+
constructor(serialization, builder) {
|
32
|
+
this.builder = builder;
|
33
|
+
this.serialization = serialization;
|
34
|
+
}
|
35
|
+
static new(serialization, builder) {
|
36
|
+
return new _RemoteTransaction(serialization, builder);
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Transaction serialization
|
40
|
+
* @type {S}
|
41
|
+
*/
|
42
|
+
serialization;
|
43
|
+
sign() {
|
44
|
+
return this.builder.sign(this);
|
45
|
+
}
|
46
|
+
signAndSubmit() {
|
47
|
+
return this.sign().then((srt) => srt.submit());
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
// src/builders/SplashRemoteBuilder.ts
|
52
|
+
var SplashRemoteBuilder = class _SplashRemoteBuilder {
|
53
|
+
static new(api) {
|
54
|
+
return new _SplashRemoteBuilder(api);
|
55
|
+
}
|
56
|
+
api;
|
57
|
+
constructor(api) {
|
58
|
+
this.api = api;
|
59
|
+
}
|
60
|
+
sign() {
|
61
|
+
throw new Error("not implemented.");
|
62
|
+
}
|
63
|
+
submit() {
|
64
|
+
throw new Error("not implemented.");
|
65
|
+
}
|
66
|
+
trade() {
|
67
|
+
return Promise.resolve(RemoteTransaction.new("", this));
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
// src/core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts
|
72
|
+
var SignedRemoteTransaction = class _SignedRemoteTransaction {
|
73
|
+
constructor(serialization, builder) {
|
74
|
+
this.builder = builder;
|
75
|
+
this.serialization = serialization;
|
76
|
+
}
|
77
|
+
static new(serialization, builder) {
|
78
|
+
return new _SignedRemoteTransaction(serialization, builder);
|
79
|
+
}
|
80
|
+
/**
|
81
|
+
* Transaction serialization
|
82
|
+
* @type {S}
|
83
|
+
*/
|
84
|
+
serialization;
|
85
|
+
submit() {
|
86
|
+
return this.builder.submit(this);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
90
|
+
0 && (module.exports = {
|
91
|
+
RemoteTransaction,
|
92
|
+
SignedRemoteTransaction,
|
93
|
+
SplashRemoteBuilder
|
94
|
+
});
|
package/dist/index.d.cts
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
import { Api, Backend, SplashBackend } from '@splashprotocol/api';
|
2
|
+
import { TransactionHash, CborHexString } from '@splashprotocol/core';
|
3
|
+
|
4
|
+
declare class SignedRemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
|
5
|
+
private builder;
|
6
|
+
static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): SignedRemoteTransaction<S, RB>;
|
7
|
+
/**
|
8
|
+
* Transaction serialization
|
9
|
+
* @type {S}
|
10
|
+
*/
|
11
|
+
readonly serialization: S;
|
12
|
+
private constructor();
|
13
|
+
submit(): Promise<TransactionHash>;
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Remote transaction representation
|
18
|
+
*/
|
19
|
+
declare class RemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
|
20
|
+
private builder;
|
21
|
+
static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): RemoteTransaction<S, RB>;
|
22
|
+
/**
|
23
|
+
* Transaction serialization
|
24
|
+
* @type {S}
|
25
|
+
*/
|
26
|
+
readonly serialization: S;
|
27
|
+
private constructor();
|
28
|
+
sign(): Promise<SignedRemoteTransaction<S, RB>>;
|
29
|
+
signAndSubmit(): Promise<TransactionHash>;
|
30
|
+
}
|
31
|
+
|
32
|
+
interface RemoteBuilder<A extends Api<Backend<{}>>, S> {
|
33
|
+
readonly api: A;
|
34
|
+
sign(tx: RemoteTransaction<S, RemoteBuilder<A, S>>): Promise<SignedRemoteTransaction<S, RemoteBuilder<A, S>>>;
|
35
|
+
submit(signedTx: SignedRemoteTransaction<S, RemoteBuilder<A, S>>): Promise<TransactionHash>;
|
36
|
+
}
|
37
|
+
|
38
|
+
declare class SplashRemoteBuilder implements RemoteBuilder<Api<SplashBackend>, CborHexString> {
|
39
|
+
static new(api: Api<SplashBackend>): SplashRemoteBuilder;
|
40
|
+
readonly api: Api<SplashBackend>;
|
41
|
+
private constructor();
|
42
|
+
sign(): Promise<SignedRemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
|
43
|
+
submit(): Promise<TransactionHash>;
|
44
|
+
trade(): Promise<RemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
|
45
|
+
}
|
46
|
+
|
47
|
+
export { type RemoteBuilder, RemoteTransaction, SignedRemoteTransaction, SplashRemoteBuilder };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
import { Api, Backend, SplashBackend } from '@splashprotocol/api';
|
2
|
+
import { TransactionHash, CborHexString } from '@splashprotocol/core';
|
3
|
+
|
4
|
+
declare class SignedRemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
|
5
|
+
private builder;
|
6
|
+
static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): SignedRemoteTransaction<S, RB>;
|
7
|
+
/**
|
8
|
+
* Transaction serialization
|
9
|
+
* @type {S}
|
10
|
+
*/
|
11
|
+
readonly serialization: S;
|
12
|
+
private constructor();
|
13
|
+
submit(): Promise<TransactionHash>;
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Remote transaction representation
|
18
|
+
*/
|
19
|
+
declare class RemoteTransaction<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>> {
|
20
|
+
private builder;
|
21
|
+
static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(serialization: S, builder: RB): RemoteTransaction<S, RB>;
|
22
|
+
/**
|
23
|
+
* Transaction serialization
|
24
|
+
* @type {S}
|
25
|
+
*/
|
26
|
+
readonly serialization: S;
|
27
|
+
private constructor();
|
28
|
+
sign(): Promise<SignedRemoteTransaction<S, RB>>;
|
29
|
+
signAndSubmit(): Promise<TransactionHash>;
|
30
|
+
}
|
31
|
+
|
32
|
+
interface RemoteBuilder<A extends Api<Backend<{}>>, S> {
|
33
|
+
readonly api: A;
|
34
|
+
sign(tx: RemoteTransaction<S, RemoteBuilder<A, S>>): Promise<SignedRemoteTransaction<S, RemoteBuilder<A, S>>>;
|
35
|
+
submit(signedTx: SignedRemoteTransaction<S, RemoteBuilder<A, S>>): Promise<TransactionHash>;
|
36
|
+
}
|
37
|
+
|
38
|
+
declare class SplashRemoteBuilder implements RemoteBuilder<Api<SplashBackend>, CborHexString> {
|
39
|
+
static new(api: Api<SplashBackend>): SplashRemoteBuilder;
|
40
|
+
readonly api: Api<SplashBackend>;
|
41
|
+
private constructor();
|
42
|
+
sign(): Promise<SignedRemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
|
43
|
+
submit(): Promise<TransactionHash>;
|
44
|
+
trade(): Promise<RemoteTransaction<CborHexString, RemoteBuilder<Api<SplashBackend>, CborHexString>>>;
|
45
|
+
}
|
46
|
+
|
47
|
+
export { type RemoteBuilder, RemoteTransaction, SignedRemoteTransaction, SplashRemoteBuilder };
|
package/dist/index.js
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
// src/core/models/RemoteTransaction/RemoteTransaction.ts
|
2
|
+
var RemoteTransaction = class _RemoteTransaction {
|
3
|
+
constructor(serialization, builder) {
|
4
|
+
this.builder = builder;
|
5
|
+
this.serialization = serialization;
|
6
|
+
}
|
7
|
+
static new(serialization, builder) {
|
8
|
+
return new _RemoteTransaction(serialization, builder);
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Transaction serialization
|
12
|
+
* @type {S}
|
13
|
+
*/
|
14
|
+
serialization;
|
15
|
+
sign() {
|
16
|
+
return this.builder.sign(this);
|
17
|
+
}
|
18
|
+
signAndSubmit() {
|
19
|
+
return this.sign().then((srt) => srt.submit());
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
// src/builders/SplashRemoteBuilder.ts
|
24
|
+
var SplashRemoteBuilder = class _SplashRemoteBuilder {
|
25
|
+
static new(api) {
|
26
|
+
return new _SplashRemoteBuilder(api);
|
27
|
+
}
|
28
|
+
api;
|
29
|
+
constructor(api) {
|
30
|
+
this.api = api;
|
31
|
+
}
|
32
|
+
sign() {
|
33
|
+
throw new Error("not implemented.");
|
34
|
+
}
|
35
|
+
submit() {
|
36
|
+
throw new Error("not implemented.");
|
37
|
+
}
|
38
|
+
trade() {
|
39
|
+
return Promise.resolve(RemoteTransaction.new("", this));
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
// src/core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts
|
44
|
+
var SignedRemoteTransaction = class _SignedRemoteTransaction {
|
45
|
+
constructor(serialization, builder) {
|
46
|
+
this.builder = builder;
|
47
|
+
this.serialization = serialization;
|
48
|
+
}
|
49
|
+
static new(serialization, builder) {
|
50
|
+
return new _SignedRemoteTransaction(serialization, builder);
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Transaction serialization
|
54
|
+
* @type {S}
|
55
|
+
*/
|
56
|
+
serialization;
|
57
|
+
submit() {
|
58
|
+
return this.builder.submit(this);
|
59
|
+
}
|
60
|
+
};
|
61
|
+
export {
|
62
|
+
RemoteTransaction,
|
63
|
+
SignedRemoteTransaction,
|
64
|
+
SplashRemoteBuilder
|
65
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"name": "@splashprotocol/remote-builder",
|
3
|
+
"version": "2.0.0-beta.6",
|
4
|
+
"type": "module",
|
5
|
+
"description": "Api client of splash protocol",
|
6
|
+
"scripts": {
|
7
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
8
|
+
"test": "jest"
|
9
|
+
},
|
10
|
+
"main": "./dist/index.js",
|
11
|
+
"types": "./dist/index.d.ts",
|
12
|
+
"exports": {
|
13
|
+
".": {
|
14
|
+
"require": "./dist/index.cjs",
|
15
|
+
"import": "./dist/index.js",
|
16
|
+
"types": "./dist/index.d.ts"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"private": false,
|
20
|
+
"devDependencies": {
|
21
|
+
"@types/jest": "^29.5.13",
|
22
|
+
"jest": "^29.7.0",
|
23
|
+
"jest-node-exports-resolver": "^1.1.6",
|
24
|
+
"ts-jest": "^29.2.5",
|
25
|
+
"tsup": "^8.3.0",
|
26
|
+
"typescript": "^5.6.2"
|
27
|
+
},
|
28
|
+
"jest": {
|
29
|
+
"preset": "ts-jest",
|
30
|
+
"testEnvironment": "node",
|
31
|
+
"testMatch": [
|
32
|
+
"**/*.spec.ts"
|
33
|
+
]
|
34
|
+
},
|
35
|
+
"peerDependencies": {
|
36
|
+
"@splashprotocol/api": "2.0.0-beta.4",
|
37
|
+
"@splashprotocol/core": "2.0.0-beta.4"
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { RemoteBuilder } from '../core/types/RemoteBuilder.ts';
|
2
|
+
import { Api, SplashBackend } from '@splashprotocol/api';
|
3
|
+
import { RemoteTransaction } from '../core/models/RemoteTransaction/RemoteTransaction.ts';
|
4
|
+
import { CborHexString, TransactionHash } from '@splashprotocol/core';
|
5
|
+
import { SignedRemoteTransaction } from '../core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
|
6
|
+
|
7
|
+
export class SplashRemoteBuilder
|
8
|
+
implements RemoteBuilder<Api<SplashBackend>, CborHexString>
|
9
|
+
{
|
10
|
+
static new(api: Api<SplashBackend>): SplashRemoteBuilder {
|
11
|
+
return new SplashRemoteBuilder(api);
|
12
|
+
}
|
13
|
+
|
14
|
+
readonly api: Api<SplashBackend>;
|
15
|
+
|
16
|
+
private constructor(api: Api<SplashBackend>) {
|
17
|
+
this.api = api;
|
18
|
+
}
|
19
|
+
|
20
|
+
sign(): Promise<
|
21
|
+
SignedRemoteTransaction<
|
22
|
+
CborHexString,
|
23
|
+
RemoteBuilder<Api<SplashBackend>, CborHexString>
|
24
|
+
>
|
25
|
+
> {
|
26
|
+
throw new Error('not implemented.');
|
27
|
+
}
|
28
|
+
|
29
|
+
submit(): Promise<TransactionHash> {
|
30
|
+
throw new Error('not implemented.');
|
31
|
+
}
|
32
|
+
|
33
|
+
trade(): Promise<
|
34
|
+
RemoteTransaction<
|
35
|
+
CborHexString,
|
36
|
+
RemoteBuilder<Api<SplashBackend>, CborHexString>
|
37
|
+
>
|
38
|
+
> {
|
39
|
+
return Promise.resolve(RemoteTransaction.new('', this));
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { RemoteTransaction } from './RemoteTransaction.ts';
|
2
|
+
import { builderEmulator } from '../../../mocks/RemoteBuilderEmulator.ts';
|
3
|
+
import { SignedRemoteTransaction } from '../SignedRemoteTransaction/SignedRemoteTransaction.ts';
|
4
|
+
|
5
|
+
test('should creates valid instance of RemoteTransaction', async () => {
|
6
|
+
const remoteTransaction = RemoteTransaction.new('unsigned', builderEmulator);
|
7
|
+
|
8
|
+
expect(remoteTransaction).toBeInstanceOf(RemoteTransaction);
|
9
|
+
expect(remoteTransaction.serialization).toBe('unsigned');
|
10
|
+
});
|
11
|
+
|
12
|
+
test('sign should returns signed transaction', async () => {
|
13
|
+
const remoteTransaction = RemoteTransaction.new('unsigned', builderEmulator);
|
14
|
+
const signedRemoteTransaction = await remoteTransaction.sign();
|
15
|
+
|
16
|
+
expect(signedRemoteTransaction).toBeInstanceOf(SignedRemoteTransaction);
|
17
|
+
expect(signedRemoteTransaction.serialization).toBe('signed');
|
18
|
+
});
|
19
|
+
|
20
|
+
test('signAndSubmit should returns transaction hash', async () => {
|
21
|
+
const remoteTransaction = RemoteTransaction.new('unsigned', builderEmulator);
|
22
|
+
const hash = await remoteTransaction.signAndSubmit();
|
23
|
+
|
24
|
+
expect(hash).toBe('submitted');
|
25
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { RemoteBuilder } from '../../types/RemoteBuilder.ts';
|
2
|
+
import { Api, Backend } from '@splashprotocol/api';
|
3
|
+
import { SignedRemoteTransaction } from '../SignedRemoteTransaction/SignedRemoteTransaction.ts';
|
4
|
+
import { TransactionHash } from '@splashprotocol/core';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Remote transaction representation
|
8
|
+
*/
|
9
|
+
export class RemoteTransaction<
|
10
|
+
S,
|
11
|
+
RB extends RemoteBuilder<Api<Backend<{}>>, S>,
|
12
|
+
> {
|
13
|
+
static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(
|
14
|
+
serialization: S,
|
15
|
+
builder: RB,
|
16
|
+
): RemoteTransaction<S, RB> {
|
17
|
+
return new RemoteTransaction(serialization, builder);
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Transaction serialization
|
22
|
+
* @type {S}
|
23
|
+
*/
|
24
|
+
readonly serialization: S;
|
25
|
+
|
26
|
+
private constructor(
|
27
|
+
serialization: S,
|
28
|
+
private builder: RB,
|
29
|
+
) {
|
30
|
+
this.serialization = serialization;
|
31
|
+
}
|
32
|
+
|
33
|
+
sign(): Promise<SignedRemoteTransaction<S, RB>> {
|
34
|
+
return this.builder.sign(this) as any;
|
35
|
+
}
|
36
|
+
|
37
|
+
signAndSubmit(): Promise<TransactionHash> {
|
38
|
+
return this.sign().then((srt) => srt.submit());
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { builderEmulator } from '../../../mocks/RemoteBuilderEmulator.ts';
|
2
|
+
import { SignedRemoteTransaction } from './SignedRemoteTransaction.ts';
|
3
|
+
|
4
|
+
test('should creates valid instance of SignedRemoteTransaction', () => {
|
5
|
+
const signedRemoteTransaction = SignedRemoteTransaction.new(
|
6
|
+
'signed',
|
7
|
+
builderEmulator,
|
8
|
+
);
|
9
|
+
|
10
|
+
expect(signedRemoteTransaction).toBeInstanceOf(SignedRemoteTransaction);
|
11
|
+
expect(signedRemoteTransaction.serialization).toBe('signed');
|
12
|
+
});
|
13
|
+
|
14
|
+
test('submit should returns transaction hash', async () => {
|
15
|
+
const signedRemoteTransaction = SignedRemoteTransaction.new(
|
16
|
+
'signed',
|
17
|
+
builderEmulator,
|
18
|
+
);
|
19
|
+
|
20
|
+
expect(await signedRemoteTransaction.submit()).toBe('submitted');
|
21
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { RemoteBuilder } from '../../types/RemoteBuilder.ts';
|
2
|
+
import { Api, Backend } from '@splashprotocol/api';
|
3
|
+
import { TransactionHash } from '@splashprotocol/core';
|
4
|
+
|
5
|
+
export class SignedRemoteTransaction<
|
6
|
+
S,
|
7
|
+
RB extends RemoteBuilder<Api<Backend<{}>>, S>,
|
8
|
+
> {
|
9
|
+
static new<S, RB extends RemoteBuilder<Api<Backend<{}>>, S>>(
|
10
|
+
serialization: S,
|
11
|
+
builder: RB,
|
12
|
+
): SignedRemoteTransaction<S, RB> {
|
13
|
+
return new SignedRemoteTransaction(serialization, builder);
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Transaction serialization
|
18
|
+
* @type {S}
|
19
|
+
*/
|
20
|
+
readonly serialization: S;
|
21
|
+
|
22
|
+
private constructor(
|
23
|
+
serialization: S,
|
24
|
+
private builder: RB,
|
25
|
+
) {
|
26
|
+
this.serialization = serialization;
|
27
|
+
}
|
28
|
+
|
29
|
+
submit(): Promise<TransactionHash> {
|
30
|
+
return this.builder.submit(this);
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { Api, Backend } from '@splashprotocol/api';
|
2
|
+
import { RemoteTransaction } from '../models/RemoteTransaction/RemoteTransaction.ts';
|
3
|
+
import { SignedRemoteTransaction } from '../models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
|
4
|
+
import { TransactionHash } from '@splashprotocol/core';
|
5
|
+
|
6
|
+
export interface RemoteBuilder<A extends Api<Backend<{}>>, S> {
|
7
|
+
readonly api: A;
|
8
|
+
|
9
|
+
sign(
|
10
|
+
tx: RemoteTransaction<S, RemoteBuilder<A, S>>,
|
11
|
+
): Promise<SignedRemoteTransaction<S, RemoteBuilder<A, S>>>;
|
12
|
+
|
13
|
+
submit(
|
14
|
+
signedTx: SignedRemoteTransaction<S, RemoteBuilder<A, S>>,
|
15
|
+
): Promise<TransactionHash>;
|
16
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Backend } from '@splashprotocol/api';
|
2
|
+
import { AssetInfoMetadata, Network } from '@splashprotocol/core';
|
3
|
+
|
4
|
+
export class BackendEmulator implements Backend<BackendEmulator> {
|
5
|
+
network: Network = 'mainnet';
|
6
|
+
|
7
|
+
getAssetMetadata(): Promise<AssetInfoMetadata | undefined> {
|
8
|
+
throw new Error('Method not implemented.');
|
9
|
+
}
|
10
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { RemoteBuilder } from '../core/types/RemoteBuilder.ts';
|
2
|
+
import { BackendEmulator } from './BackendEmulator.ts';
|
3
|
+
import { HexString, TransactionHash } from '@splashprotocol/core';
|
4
|
+
import { Api, createApi } from '@splashprotocol/api';
|
5
|
+
import { SignedRemoteTransaction } from '../core/models/SignedRemoteTransaction/SignedRemoteTransaction.ts';
|
6
|
+
|
7
|
+
export class RemoteBuilderEmulator
|
8
|
+
implements RemoteBuilder<Api<BackendEmulator>, HexString>
|
9
|
+
{
|
10
|
+
sign(): Promise<
|
11
|
+
SignedRemoteTransaction<
|
12
|
+
HexString,
|
13
|
+
RemoteBuilder<Api<BackendEmulator>, HexString>
|
14
|
+
>
|
15
|
+
> {
|
16
|
+
return Promise.resolve(SignedRemoteTransaction.new('signed', this));
|
17
|
+
}
|
18
|
+
submit(): Promise<TransactionHash> {
|
19
|
+
return Promise.resolve('submitted');
|
20
|
+
}
|
21
|
+
|
22
|
+
constructor(public api: Api<BackendEmulator>) {}
|
23
|
+
}
|
24
|
+
|
25
|
+
const api = createApi(new BackendEmulator());
|
26
|
+
export const builderEmulator = new RemoteBuilderEmulator(api);
|