Skip to content

Commit d3c42c6

Browse files
Added README.md
The server only allows localhost to access the /mine and /addInvoice endpoints. The P2PServer now relays the sent message to all its peers (except the one that sent it).
1 parent f059f11 commit d3c42c6

20 files changed

+158
-58
lines changed

Diff for: BlockChain/BlockChain.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: BlockChain/BlockChain.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: BlockChain/BlockChain.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import isEqual from "lodash/isEqual";
21
import {freezeClass} from "../freeze";
32
import Block, {Data} from "./Block";
43

@@ -14,7 +13,7 @@ export default class BlockChain {
1413
const chainLen = chain.length;
1514
if (chainLen < 2) return false;
1615

17-
if (!isEqual(chain[0], Block.genesis())) return false;
16+
if (JSON.stringify(chain[0]) !== JSON.stringify(Block.genesis())) return false;
1817

1918
for (let i = 1; i < chainLen; i++) {
2019
const lastBlock = chain[i - 1];

Diff for: README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# blockchain-based-invoice-management-system
2+
3+
A blockchain based invoice management system for vendors to track all their customers' invoices.
4+
5+
This project is the CLI API of the “blockchain-based-invoice-management-system”.
6+
7+
This application is to be used by manufacturers and vendors so as to keep a log of all their customers’ invoices.
8+
Any shopkeeper can add an invoice, which will be signed by the shopkeeper’s private key, so as to prevent tampering by other shopkeepers. This invoice will be broadcasted to all the shopkeeper’s peers.
9+
Any vendor can mine the set of invoices in the pool of invoices. This will add the set of invoices to the block chain thereby confirming the invoices in the pool.
10+
11+
A vendor will only have to input the invoice details like the invoice number, the purchaser’s details and the product’s details.
12+
The purchase’s details are phone number, name, and whether or not the purchaser is an another vendor.
13+
The product details only need to be the name, quantity, cost, and tax percentage.
14+
An individual product’s tax price and total cost will be calculated by the application. The invoice’s grand total cost will also be automatically calculated.
15+
16+
## Getting started
17+
18+
First run:
19+
20+
```
21+
yarn install
22+
```
23+
24+
To install all the dependencies
25+
Then run:
26+
27+
```
28+
tsc
29+
```
30+
31+
To convert all the TS file to JS files.
32+
33+
### Generating keys
34+
35+
```
36+
yarn app gen-keys --public-key-file-path <public-key-file=sign-public-key.pem> --private-key-file-path <private-key-file=sign-private-key.pem>
37+
```
38+
39+
And then enter the password in the prompt shown.
40+
Or input the password with `--password <password>`.
41+
42+
### Starting the server API
43+
44+
```
45+
yarn app p2p --port <server-api-port> --p2p-port <p2p-socket-port> --peers ws:\\<peer-address>:<p2p-socket-port>[,ws:\\<peer-address>:<p2p-socket-port>...] --public-key-file-path <public-key-file=sign-public-key.pem> --private-key-file-path <private-key-file=sign-private-key.pem>
46+
```
47+
48+
And then enter the password to decrypt the private key in the prompt then shown.
49+
Or input the password with `--password <password>`.

Diff for: Wallet/Invoice.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Wallet/Invoice.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import crypto from "crypto";
22
import cloneDeep from "lodash/cloneDeep";
3-
import {Inv, RecInv} from "./Inv";
43
import {freezeClass} from "../freeze";
54
import {deepFreeze, DeepReadonly, DeepWriteable} from "../utils";
5+
import {Inv, RecInv} from "./Inv";
66
import InvalidPhoneNumberError from "./InvalidPhoneNumberError";
77
import Wallet from "./Wallet";
88

@@ -26,7 +26,7 @@ export default class Invoice {
2626
this.publicKey = invoice_.publicKey;
2727
} else {
2828
const a_ = a as RecInv;
29-
if(a_.purchaser.phoneNumber.match(/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/) == null){
29+
if (a_.purchaser.phoneNumber.match(/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/) == null) {
3030
throw new InvalidPhoneNumberError(`Invalid phone number: ${a_.purchaser.phoneNumber}`);
3131
}
3232
const invoice_ = cloneDeep(a) as DeepWriteable<Inv>;
@@ -59,7 +59,7 @@ export default class Invoice {
5959
}
6060

6161
static verifyInv (invoice: Inv) {
62-
if(invoice.purchaser.phoneNumber.match(/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/) == null){
62+
if (invoice.purchaser.phoneNumber.match(/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/) == null) {
6363
return false;
6464
}
6565
let totalCost = 0;

Diff for: Wallet/InvoicePool.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Wallet/InvoicePool.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Wallet/InvoicePool.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("InvoicePool", function () {
5252
describe("And adding it again", function () {
5353
it('should do nothing', function () {
5454
const oldPool = cloneDeep(pool);
55-
expect(pool.addInvoice(invoice)).toBe(invoice);
55+
pool.addInvoice(invoice)
5656
expect(oldPool).toEqual(pool);
5757
});
5858
})

Diff for: Wallet/InvoicePool.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import Invoice from "./Invoice";
55
export default class InvoicePool {
66
invoices: Invoice[] = [];
77

8-
addInvoice (invoice: Invoice): Invoice {
8+
addInvoice (invoice: Invoice): boolean {
99
if (this.invoices.find(
1010
value => value.invoice.invoiceNumber === invoice.invoice.invoiceNumber
1111
) == null && Invoice.verify(invoice)) {
1212
this.invoices.push(invoice);
13+
return true;
1314
}
14-
return invoice;
15+
return false;
1516
}
1617

1718
getValidInvoices () {

Diff for: Wallet/Wallet.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Wallet/Wallet.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Wallet/Wallet.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import crypto from "crypto";
2-
import {RecInv, Invoice, InvoicePool} from ".";
2+
import {Invoice, InvoicePool, RecInv} from ".";
33
import {freezeClass} from "../freeze";
44

55
@freezeClass
@@ -23,6 +23,8 @@ export default class Wallet {
2323
}
2424

2525
addInvoiceToPool (pool: InvoicePool, invoice: RecInv) {
26-
return pool.addInvoice(new Invoice(invoice, this));
26+
const invoice_ = new Invoice(invoice, this);
27+
pool.addInvoice(invoice_);
28+
return invoice_;
2729
}
2830
}

0 commit comments

Comments
 (0)