-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [ergo-graphql client] add initial package structure (#39) * add initial package structure * fix jsdoc grammar * fix lockfile * add gql client * basic implementation of gql-client * add pnpm-lock file * fix comments * add mutation implementation * Update packages/graphql-client/src/graphqlClient.ts Co-authored-by: Alison Robson <87387688+arobsn@users.noreply.github.com> * fix comments * add internal graphql client * remove urql * complete tests * add more tests * lint code * fix coverage --------- Co-authored-by: Alison Robson <87387688+arobsn@users.noreply.github.com>
- Loading branch information
1 parent
80daecc
commit 03b8764
Showing
20 changed files
with
4,051 additions
and
1,297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { FleetError, NotSupportedError } from "./error"; | ||
|
||
describe("Errors", () => { | ||
it("Should construct errors", () => { | ||
const errorMsg = "error smoke test"; | ||
|
||
expect(new FleetError().name).to.be.equal("FleetError"); | ||
expect(new NotSupportedError().name).to.be.equal("NotSupportedError"); | ||
|
||
expect(() => { | ||
throw new FleetError(errorMsg); | ||
}).to.throw(FleetError, errorMsg); | ||
|
||
expect(() => { | ||
throw new NotSupportedError(errorMsg); | ||
}).to.throw(NotSupportedError, errorMsg); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export class FleetError extends Error { | ||
constructor(message?: string) { | ||
super(message); | ||
|
||
Object.setPrototypeOf(this, new.target.prototype); | ||
this.name = new.target.name; | ||
} | ||
} | ||
|
||
export class NotSupportedError extends FleetError { | ||
constructor(message?: string) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./utils"; | ||
export * from "./types"; | ||
export * from "./models"; | ||
export * from "./error"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { RequireAtLeastOne } from "type-fest"; | ||
import { BlockHeader } from "./block"; | ||
import { Box } from "./boxes"; | ||
import { HexString } from "./common"; | ||
import { SignedTransaction, TransactionId, UnsignedTransaction } from "./transactions"; | ||
|
||
export type QueryBase = { | ||
take?: number; | ||
skip?: number; | ||
}; | ||
|
||
export type BoxQuery<W extends BoxWhere> = { | ||
where: RequireAtLeastOne<W>; | ||
|
||
/** | ||
* Determines if it should include unspent boxes from the mempool. | ||
* @default true | ||
*/ | ||
includeUnconfirmed?: boolean; | ||
} & QueryBase; | ||
|
||
export type BoxWhere = { | ||
/** Base16-encoded BoxId */ | ||
boxId?: HexString; | ||
|
||
/** Base16-encoded ErgoTree or Base58-encoded address */ | ||
contract?: HexString; | ||
|
||
/** Base16-encoded contract template */ | ||
template?: HexString; | ||
|
||
/** Base16-encoded TokenId */ | ||
tokenId?: HexString; | ||
}; | ||
|
||
export type ChainClientBox = Box<bigint> & { | ||
confirmed: boolean; | ||
}; | ||
|
||
export interface IChainDataClient<B extends BoxWhere> { | ||
/** | ||
* Get unspent boxes from the blockchain. | ||
*/ | ||
getUnspentBoxes(query: BoxQuery<B>): Promise<ChainClientBox[]>; | ||
|
||
/** | ||
* Get the last `n` block headers from the blockchain. | ||
*/ | ||
getLastHeaders(count: number): Promise<BlockHeader[]>; | ||
|
||
/** | ||
* Check for transaction validity without broadcasting it to the network. | ||
*/ | ||
checkTransaction(transaction: SignedTransaction): Promise<boolean>; | ||
|
||
/** | ||
* Broadcast a transaction to the network. | ||
*/ | ||
submitTransaction(transaction: SignedTransaction): Promise<TransactionId>; | ||
|
||
/** | ||
* Evaluate a transaction and return Base16-encoded evaluation result. | ||
*/ | ||
reduceTransaction(transaction: UnsignedTransaction): Promise<HexString>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Nautilus Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @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) | ||
|
||
Blockchain data client for ergo-graphql. | ||
|
||
## Build | ||
```sh | ||
pnpm --filter graphql-client build | ||
``` | ||
|
||
## Test | ||
```sh | ||
pnpm test:unit graphql-client | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "@fleet-sdk/graphql-client", | ||
"version": "0.0.0", | ||
"description": "Blockchain data client for ergo-graphql", | ||
"main": "./dist/index.cjs.js", | ||
"module": "./dist/index.esm.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"require": "./dist/index.cjs.js", | ||
"import": "./dist/index.esm.js" | ||
}, | ||
"sideEffects": true, | ||
"repository": "fleet-sdk/fleet", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true | ||
}, | ||
"keywords": [ | ||
"ergo", | ||
"blockchain", | ||
"crypto" | ||
], | ||
"scripts": { | ||
"build": "tsup --config ../../tsup.config.ts" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"dependencies": { | ||
"@fleet-sdk/common": "workspace:^", | ||
"@fleet-sdk/core": "workspace:^" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"!**/*.spec.*", | ||
"!**/*.json", | ||
"!tests", | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"devDependencies": { | ||
"@ergo-graphql/types": "^0.5.0" | ||
} | ||
} |
Oops, something went wrong.