diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c8b5e..aee5594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v2.1.0 + +### Added + +- Added `process`, `work_cancel`, & `work_generate` RPC support. + +### Changed + +- Changed type definition of `SubType` to include 'open' and 'epoch' types. + ## v2.0.2 ### Fixed diff --git a/LICENSE.md b/LICENSE.md index c345e1c..c78edcd 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 [dev-ptera](https://github.com/dev-ptera) +Copyright (c) 2022 [dev-ptera](https://github.com/dev-ptera) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index e78e76b..c942e02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dev-ptera/nano-node-rpc", - "version": "2.0.2", + "version": "2.1.0", "description": "A typescript nanocurrency client used to make node RPC calls.", "main": "dist/index.js", "license": "MIT", diff --git a/src/client/nano-client.ts b/src/client/nano-client.ts index 37776f4..a0b2873 100644 --- a/src/client/nano-client.ts +++ b/src/client/nano-client.ts @@ -1,5 +1,6 @@ import axios, { AxiosResponse } from 'axios'; import * as RPC from '../types/rpc-response'; +import { ProcessBody } from '../types/rpc-body'; /** * @class NanoClient @@ -433,6 +434,14 @@ export class NanoClient { }); } + /** + * Publish block to the network + * @param {body} ProcessBody - Transaction details. + */ + process(body: ProcessBody): Promise { + return this._send('process', body); + } + /** * Divide a raw amount down by the rai ratio. * @param {string} amount - An amount to be converted. @@ -495,9 +504,25 @@ export class NanoClient { } /** - * Return node uptime in seconds + * Return node uptime in seconds. */ uptime(): Promise { return this._send('uptime'); } + + /** + * Stop generating work for block. + * @param {string} hash - Hash supplied in a previous work generate request. + */ + work_cancel(hash: string): Promise { + return this._send('work_cancel', { hash }); + } + + /** + * Generates work for block. + * @param {string} hash - The frontier of the account or in the case of an open block, the public key representation of the account which can be found with account_key. + */ + work_generate(hash: string): Promise { + return this._send('work_generate', { hash }); + } } diff --git a/src/types/index.ts b/src/types/index.ts index dc31062..6b4609a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1 +1,2 @@ export * from './rpc-response'; +export * from './rpc-body'; diff --git a/src/types/rpc-body.ts b/src/types/rpc-body.ts new file mode 100644 index 0000000..03ff356 --- /dev/null +++ b/src/types/rpc-body.ts @@ -0,0 +1,19 @@ +import { Subtype } from './rpc-response'; + +export type ProcessBody = { + json_block?: boolean; + subtype?: Subtype; + force?: boolean; + async?: boolean; + block: { + type: string; + account: string; + previous: string; + representative: string; + balance: string; + link: string; + link_as_account?: string; + signature: string; + work: string; + }; +}; diff --git a/src/types/rpc-response.ts b/src/types/rpc-response.ts index 0ce2fd1..910e73b 100644 --- a/src/types/rpc-response.ts +++ b/src/types/rpc-response.ts @@ -1,7 +1,9 @@ export type ErrorResponse = { error: string; }; -export type Subtype = 'send' | 'receive' | 'change'; + +export type Subtype = 'send' | 'receive' | 'change' | 'open' | 'epoch'; + export type AccountBalanceResponse = { balance: string; pending: string; @@ -194,6 +196,9 @@ export type PeersResponse = { [ip: string]: T extends PeersResponseDetails ? PeersResponseDetails : string; }; }; +export type ProcessResponse = { + hash: string; +}; export type RepresentativesResponse = { representatives: { [account: string]: string; @@ -228,3 +233,12 @@ export type VersionResponse = { export type UptimeResponse = { seconds: string; }; +export type WorkCancelResponse = { + success: ''; +}; +export type WorkGenerateResponse = { + work: string; + difficulty: string; + multiplier: string; + hash: string; +};