-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs website init * setup front matter for docs website * added testcontainers overview and usage docs * split testcontainers installation * rename getting-started to introduction * added project introduction * structured docs website * completed overview and design docs * completed usage docs for jellyfish * added wallet.md and mining.md for features implemented
- Loading branch information
Showing
27 changed files
with
44,956 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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,20 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Production | ||
/build | ||
|
||
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
|
||
# Misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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,25 @@ | ||
# jellyfish/website | ||
|
||
> This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. | ||
## Installation | ||
|
||
```console | ||
npm i | ||
``` | ||
|
||
## Local Development | ||
|
||
```console | ||
npm run start | ||
``` | ||
|
||
This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. | ||
|
||
## Build | ||
|
||
```console | ||
npm run build | ||
``` | ||
|
||
This command generates static content into the `build` directory and can be served using any static contents hosting service. |
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,3 @@ | ||
module.exports = { | ||
presets: [require.resolve('@docusaurus/core/lib/babel/preset')] | ||
} |
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,30 @@ | ||
--- | ||
id: introduction | ||
title: Introduction | ||
sidebar_label: Introduction | ||
slug: / | ||
--- | ||
|
||
A collection of TypeScript + JavaScript tools and libraries for DeFiChain developers to build decentralized finance on Bitcoin. | ||
Consisting of 4 packages with more to be added in the future, the jellyfish project allow DeFiChain developers to build decentralized apps that are modern, easy to use and easy to test. | ||
|
||
Jellyfish follows a monorepo methodology, all maintained packages are in the same repo and published with the same version tag. | ||
|
||
## Packages | ||
|
||
* `@defichain/jellyfish` bundled usage entrypoint with conventional defaults for 4 bundles: umd, esm, cjs | ||
and d.ts | ||
* `@defichain/jellyfish-core` is a protocol agnostic DeFiChain client interfaces, with a "foreign function interface" | ||
design. | ||
* `@defichain/jellyfish-jsonrpc` implements the [JSON-RPC 1.0](https://www.jsonrpc.org/specification_v1) specification. | ||
* `@defichain/testcontainers` provides a lightweight, throw away instances for DeFiD node provisioned automatically in | ||
Docker container. | ||
|
||
### Latest releases | ||
|
||
|package|@latest|@next| | ||
|---|---|---| | ||
|`@defichain/jellyfish`|[![npm](https://img.shields.io/npm/v/@defichain/jellyfish)](https://www.npmjs.com/package/@defichain/jellyfish/v/latest)|[![npm@next](https://img.shields.io/npm/v/@defichain/jellyfish/next)](https://www.npmjs.com/package/@defichain/jellyfish/v/next)| | ||
|`@defichain/jellyfish-core`|[![npm](https://img.shields.io/npm/v/@defichain/jellyfish-core)](https://www.npmjs.com/package/@defichain/jellyfish-core/v/latest)|[![npm@next](https://img.shields.io/npm/v/@defichain/jellyfish-core/next)](https://www.npmjs.com/package/@defichain/jellyfish-core/v/next)| | ||
|`@defichain/jellyfish-jsonrpc`|[![npm](https://img.shields.io/npm/v/@defichain/jellyfish-jsonrpc)](https://www.npmjs.com/package/@defichain/jellyfish-jsonrpc/v/latest)|[![npm@next](https://img.shields.io/npm/v/@defichain/jellyfish-jsonrpc/next)](https://www.npmjs.com/package/@defichain/jellyfish-jsonrpc/v/next)| | ||
|`@defichain/testcontainers`|[![npm](https://img.shields.io/npm/v/@defichain/testcontainers)](https://www.npmjs.com/package/@defichain/testcontainers/v/latest)|[![npm@next](https://img.shields.io/npm/v/@defichain/testcontainers/next)](https://www.npmjs.com/package/@defichain/testcontainers/v/next)| |
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,41 @@ | ||
--- | ||
id: mining | ||
title: Mining API | ||
sidebar_label: Mining API | ||
slug: /jellyfish/api/mining | ||
--- | ||
|
||
## getNetworkHashPerSecond | ||
|
||
Returns the estimated network hashes per second. | ||
- `nblocks` to estimate since last difficulty change. | ||
- `height` to estimate at the time of the given height. | ||
|
||
```ts | ||
getNetworkHashPerSecond (nblocks: number = 120, height: number = -1): Promise<number> | ||
``` | ||
|
||
## getMintingInfo | ||
|
||
Get minting-related information. | ||
|
||
```ts | ||
interface MintingInfo { | ||
blocks: number | ||
currentblockweight?: number | ||
currentblocktx?: number | ||
difficulty: string | ||
isoperator: boolean | ||
masternodeid?: string | ||
masternodeoperator?: string | ||
masternodestate?: 'PRE_ENABLED' | 'ENABLED' | 'PRE_RESIGNED' | 'RESIGNED' | 'PRE_BANNED' | 'BANNED' | ||
generate?: boolean | ||
mintedblocks?: number | ||
networkhashps: number | ||
pooledtx: number | ||
chain: 'main' | 'test' | 'regtest' | string | ||
warnings: string | ||
} | ||
|
||
getMintingInfo (): Promise<MintingInfo> | ||
``` |
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,17 @@ | ||
--- | ||
id: wallet | ||
title: Wallet API | ||
sidebar_label: Wallet API | ||
slug: /jellyfish/api/wallet | ||
--- | ||
|
||
## getBalance | ||
|
||
Returns the total available balance in wallet. | ||
- `minimumConfirmation` to include transactions confirmed at least this many times. | ||
- `includeWatchOnly` for watch-only wallets, otherwise | ||
- Include balance in watch-only addresses (see `importAddress`) | ||
|
||
```ts | ||
getBalance (minimumConfirmation: number = 0, includeWatchOnly: boolean = false): Promise<BigNumber> | ||
``` |
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,126 @@ | ||
--- | ||
id: design | ||
title: Jellyfish Design | ||
sidebar_label: Jellyfish Design | ||
slug: /jellyfish/design | ||
--- | ||
|
||
## Conventional defaults | ||
|
||
`@defichain/jellyfish` package provides conventional defaults and bundle all code required for dApps building. | ||
|
||
```js | ||
import { Client, HttpProvider } from '@defichain/jellyfish' | ||
|
||
// Coventional Defaults | ||
let client = new Client() | ||
|
||
// Explicit Configuration | ||
client = new Client(new HttpProvider('http://foo:bar@localhost:8554'), { | ||
timeout: 30000 | ||
}) | ||
``` | ||
|
||
## Promise-based client | ||
|
||
To prevent a "callback hell" structure where code get nested and messy; making it harder to understand. | ||
A `Promise<?>` based design is used as async/await implementation are very mature today, it brings better quality of | ||
life to modern development. | ||
|
||
```js | ||
import {Client} from '@defichain/jellyfish' | ||
|
||
const client = new Client() | ||
const {blocks} = await client.mining.getMintingInfo() | ||
``` | ||
|
||
## IEEE-754 arbitrary precision | ||
|
||
Due to the dynamic nature of the JavaScript language, it forces all number to be interpolated as IEEE-754 which can | ||
cause precision to be lost. [DeFiCh/jellyfish/issues/18](https://github.com/DeFiCh/jellyfish/issues/18) | ||
|
||
```js | ||
it('lost precision converting DFI 😥', () => { | ||
const n = 1200000000.00000001 | ||
const a = JSON.parse(JSON.stringify(n)) * 1.0e8 | ||
expect(a.toString()).toBe("120000000000000001") | ||
}); | ||
``` | ||
|
||
### `JellyfishJSON` | ||
|
||
**jellyfish-core** implements `JellyfishJSON` that allows parsing of JSON with `'lossless'`, `'bignumber'` and | ||
`'number'` numeric precision. | ||
|
||
* **'lossless'** uses LosslessJSON that parses numeric values as LosslessNumber. With LosslessNumber, one can perform | ||
regular numeric operations, and it will throw an error when this would result in losing information. | ||
* **'bignumber'** parse all numeric values as 'BigNumber' using bignumber.js library. | ||
* **'number'** parse all numeric values as 'Number' and precision will be loss if it exceeds IEEE-754 standard. | ||
|
||
|
||
As not all number parsed are significant in all context, (e.g. `mining.getMintingInfo()`), this allows jellyfish library | ||
users to use the `number` for non precision sensitive operation (e.g. `networkhashps`) and BigNumber for precision | ||
sensitive operations. | ||
|
||
### `JellyfishClient` | ||
|
||
As jellyfish is written in TypeScript, all RPC exchanges with a node are typed. BigNumber precision is used for all | ||
wallet or transaction related operations. While IEEE-754 number is used for all other arbitrary operations. | ||
|
||
```ts {3} | ||
export class Wallet { | ||
async getBalance (minimumConfirmation: number = 0, includeWatchOnly: boolean = false): Promise<BigNumber> { | ||
return await this.client.call('getbalance', ['*', minimumConfirmation, includeWatchOnly], 'bignumber') | ||
} | ||
} | ||
|
||
``` | ||
|
||
```ts {2-3,9,13} | ||
export interface MintingInfo { | ||
blocks: number | ||
currentblockweight?: number | ||
//... | ||
} | ||
|
||
export class Mining { | ||
async getNetworkHashPerSecond (nblocks: number = 120, height: number = -1): Promise<number> { | ||
return await this.client.call('getnetworkhashps', [nblocks, height], 'number') | ||
} | ||
|
||
async getMintingInfo (): Promise<MintingInfo> { | ||
return await this.client.call('getmintinginfo', [], 'number') | ||
} | ||
} | ||
``` | ||
|
||
## Protocol agnostic core | ||
|
||
JellyfishClient in `jellyfish-core` is a protocol agnostic DeFiChain client implementation with APIs separated into | ||
their category. The protocol-agnostic core enable independent communication protocols, allowing | ||
vendor-agnostic middleware adaptable to any needs. | ||
|
||
```ts | ||
export abstract class JellyfishClient { | ||
/** | ||
* A promise based procedure call handling | ||
* | ||
* @param method Name of the RPC method | ||
* @param params Array of params as RPC payload | ||
* @param precision | ||
* Numeric precision to parse RPC payload as 'lossless', 'bignumber' or 'number'. | ||
* | ||
* 'lossless' uses LosslessJSON that parses numeric values as LosslessNumber. With LosslessNumber, one can perform | ||
* regular numeric operations, and it will throw an error when this would result in losing information. | ||
* | ||
* 'bignumber' parse all numeric values as 'BigNumber' using bignumber.js library. | ||
* | ||
* 'number' parse all numeric values as 'Number' and precision will be loss if it exceeds IEEE-754 standard. | ||
* | ||
* @throws JellyfishError | ||
* @throws JellyfishRPCError | ||
* @throws JellyfishClientError | ||
*/ | ||
abstract call<T> (method: string, params: any[], precision: Precision): Promise<T> | ||
} | ||
``` |
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,23 @@ | ||
--- | ||
id: overview | ||
title: Jellyfish Overview | ||
sidebar_label: Jellyfish Overview | ||
slug: /jellyfish | ||
--- | ||
|
||
## What is jellyfish? | ||
|
||
Jellyfish is a JS library written to enable developers to develop decentralized applications on top of DeFiChain. As | ||
with all modern JavaScript projects, jellyfish follows a monorepo structure with its concerns separated. All packages | ||
maintained in this repo are published with the same version tag and follows the `DeFiCh/ain` releases. | ||
|
||
- **jellyfish** is the entrypoint for most dApps developer as it bundles and create 4 types of JavaScript modules: | ||
cjs, esm, umd and d.ts. | ||
- **jellyfish-core** represents a protocol agnostic interface of DeFiChain client with APIs separated into their | ||
category. | ||
- **jellyfish-jsonrpc** implements the jellyfish-core with the JSON-RPC 1.0 specification. | ||
|
||
Written in TypeScript, jellyfish provides first-class citizen support for TypeScript with strongly typed interfaces of | ||
DeFiChain rpc exchanges. Built using modern JavaScript approaches, it emphasises a **future-first developer experience** | ||
and backport for compatibility. The protocol-agnostic core enable independent communication protocols, allowing | ||
vendor-agnostic middleware adaptable to any needs. |
Oops, something went wrong.