Skip to content

Commit edc2836

Browse files
authored
[ergo-graphql client] add initial package structure (#39)
* add initial package structure * fix jsdoc grammar * fix lockfile
1 parent 445c463 commit edc2836

File tree

10 files changed

+213
-0
lines changed

10 files changed

+213
-0
lines changed

packages/common/src/error.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vitest";
2+
import { FleetError, NotSupportedError } from "./error";
3+
4+
describe("Errors", () => {
5+
it("Should construct errors", () => {
6+
const errorMsg = "error smoke test";
7+
8+
expect(new FleetError().name).to.be.equal("FleetError");
9+
expect(new NotSupportedError().name).to.be.equal("NotSupportedError");
10+
11+
expect(() => {
12+
throw new FleetError(errorMsg);
13+
}).to.throw(FleetError, errorMsg);
14+
15+
expect(() => {
16+
throw new NotSupportedError(errorMsg);
17+
}).to.throw(NotSupportedError, errorMsg);
18+
});
19+
});

packages/common/src/error.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class FleetError extends Error {
2+
constructor(message?: string) {
3+
super(message);
4+
5+
Object.setPrototypeOf(this, new.target.prototype);
6+
this.name = new.target.name;
7+
}
8+
}
9+
10+
export class NotSupportedError extends FleetError {
11+
constructor(message?: string) {
12+
super(message);
13+
}
14+
}

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./utils";
22
export * from "./types";
33
export * from "./models";
4+
export * from "./error";
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { RequireAtLeastOne } from "type-fest";
2+
import { BlockHeader } from "./block";
3+
import { Box } from "./boxes";
4+
import { HexString } from "./common";
5+
import { SignedTransaction, TransactionId, UnsignedTransaction } from "./transactions";
6+
7+
export type QueryBase = {
8+
take?: number;
9+
skip?: number;
10+
};
11+
12+
export type BoxQuery<W extends BoxWhere> = {
13+
where: RequireAtLeastOne<W>;
14+
15+
/**
16+
* Determines if it should include unspent boxes from the mempool.
17+
* @default true
18+
*/
19+
includeUnconfirmed?: boolean;
20+
} & QueryBase;
21+
22+
export type BoxWhere = {
23+
/** Base16-encoded BoxId */
24+
boxId?: HexString;
25+
26+
/** Base16-encoded ErgoTree or Base58-encoded address */
27+
contract?: HexString;
28+
29+
/** Base16-encoded contract template */
30+
template?: HexString;
31+
32+
/** Base16-encoded TokenId */
33+
tokenId?: HexString;
34+
};
35+
36+
export type ChainClientBox = Box<bigint> & {
37+
confirmed: boolean;
38+
};
39+
40+
export interface IChainDataClient<B extends BoxWhere> {
41+
/**
42+
* Get unspent boxes from the blockchain.
43+
*/
44+
getUnspentBoxes(query: BoxQuery<B>): Promise<ChainClientBox[]>;
45+
46+
/**
47+
* Get the last `n` block headers from the blockchain.
48+
*/
49+
getLastHeaders(count: number): Promise<BlockHeader[]>;
50+
51+
/**
52+
* Check for transaction validity without broadcasting it to the network.
53+
*/
54+
checkTransaction(transaction: SignedTransaction): Promise<boolean>;
55+
56+
/**
57+
* Broadcast a transaction to the network.
58+
*/
59+
submitTransaction(transaction: SignedTransaction): Promise<TransactionId>;
60+
61+
/**
62+
* Evaluate a transaction and return Base16-encoded evaluation result.
63+
*/
64+
reduceTransaction(transaction: UnsignedTransaction): Promise<HexString>;
65+
}

packages/common/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from "./registers";
77
export * from "./token";
88
export * from "./transactions";
99
export * from "./block";
10+
export * from "./chainClients";

packages/graphql-client/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Nautilus Team
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/graphql-client/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @fleet-sdk/graphql-client [![License](https://badgen.net/github/license/fleet-sdk/fleet/)](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [![npm](https://badgen.net/npm/v/@fleet-sdk/graphql-client)](https://www.npmjs.com/package/@fleet-sdk/graphql-client)
2+
3+
Blockchain data client for ergo-graphql.
4+
5+
## Build
6+
```sh
7+
pnpm --filter graphql-client build
8+
```
9+
10+
## Test
11+
```sh
12+
pnpm test:unit graphql-client
13+
```

packages/graphql-client/package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "@fleet-sdk/graphql-client",
3+
"version": "0.0.0",
4+
"description": "Blockchain data client for ergo-graphql",
5+
"main": "./dist/index.cjs.js",
6+
"module": "./dist/index.esm.js",
7+
"types": "./dist/index.d.ts",
8+
"exports": {
9+
"require": "./dist/index.cjs.js",
10+
"import": "./dist/index.esm.js"
11+
},
12+
"sideEffects": true,
13+
"repository": "fleet-sdk/fleet",
14+
"license": "MIT",
15+
"publishConfig": {
16+
"access": "public",
17+
"provenance": true
18+
},
19+
"keywords": [
20+
"ergo",
21+
"blockchain",
22+
"crypto"
23+
],
24+
"scripts": {
25+
"build": "tsup --config ../../tsup.config.ts"
26+
},
27+
"engines": {
28+
"node": ">=14"
29+
},
30+
"dependencies": {
31+
"@fleet-sdk/common": "workspace:^",
32+
"@fleet-sdk/core": "workspace:^",
33+
"@urql/core": "^4.1.2"
34+
},
35+
"files": [
36+
"src",
37+
"dist",
38+
"!**/*.spec.*",
39+
"!**/*.json",
40+
"!tests",
41+
"CHANGELOG.md",
42+
"LICENSE",
43+
"README.md"
44+
]
45+
}

packages/graphql-client/src/index.ts

Whitespace-only changes.

pnpm-lock.yaml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)