Skip to content

Commit

Permalink
Merge pull request #15 from dev-ptera/feature/add-new-commands
Browse files Browse the repository at this point in the history
Add new rpc commands
  • Loading branch information
dev-ptera authored Dec 30, 2022
2 parents 29e34b9 + 55208ae commit e05d6e2
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 26 additions & 1 deletion src/client/nano-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios, { AxiosResponse } from 'axios';
import * as RPC from '../types/rpc-response';
import { ProcessBody } from '../types/rpc-body';

/**
* @class NanoClient
Expand Down Expand Up @@ -433,6 +434,14 @@ export class NanoClient {
});
}

/**
* Publish block to the network
* @param {body} ProcessBody - Transaction details.
*/
process(body: ProcessBody): Promise<RPC.ProcessResponse> {
return this._send('process', body);
}

/**
* Divide a raw amount down by the rai ratio.
* @param {string} amount - An amount to be converted.
Expand Down Expand Up @@ -495,9 +504,25 @@ export class NanoClient {
}

/**
* Return node uptime in seconds
* Return node uptime in seconds.
*/
uptime(): Promise<RPC.UptimeResponse> {
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<RPC.WorkCancelResponse> {
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<RPC.WorkGenerateResponse> {
return this._send('work_generate', { hash });
}
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './rpc-response';
export * from './rpc-body';
19 changes: 19 additions & 0 deletions src/types/rpc-body.ts
Original file line number Diff line number Diff line change
@@ -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;
};
};
16 changes: 15 additions & 1 deletion src/types/rpc-response.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -194,6 +196,9 @@ export type PeersResponse<T extends PeersResponseDetails | undefined> = {
[ip: string]: T extends PeersResponseDetails ? PeersResponseDetails : string;
};
};
export type ProcessResponse = {
hash: string;
};
export type RepresentativesResponse = {
representatives: {
[account: string]: string;
Expand Down Expand Up @@ -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;
};

0 comments on commit e05d6e2

Please sign in to comment.