Skip to content

Commit e690521

Browse files
author
Saransh Sharma
committed
Transactions Model
1 parent 719d134 commit e690521

6 files changed

Lines changed: 54 additions & 40 deletions

File tree

api/controllers/AddressController.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ const AddressController = () => {
4848
return res.status(400).json({ msg: 'Bad Request: Address field is must' });
4949
};
5050

51-
const generateAddress = async(req, res) => {
51+
const generateAddress = async (req, res) => {
5252
const { body, query } = req;
5353
const walletId = body.walletId || query.walletId;
54-
if (walletId){
54+
if (walletId) {
5555
try {
5656
// We get wallet
5757
const walletFromDB = await WalletModel.findAll({
@@ -63,21 +63,20 @@ const AddressController = () => {
6363
data = await conversions(walletFromDB);
6464

6565
// We need to fetch the private key and generate public address
66-
const privateKey = new PrivateKey(data[0].privateKey)
66+
const privateKey = new PrivateKey(data[0].privateKey);
6767
const pubKey = privateKey.toPublicKey();
6868
const address = pubKey.toAddress(bitcore.Networks.livenet);
6969

7070
// Now we can save the address
7171
address = Address.create({
7272
network: 'livenet',
73-
address: address,
74-
walletId: data[0].id
73+
address,
74+
walletId: data[0].id,
7575
});
7676

7777
return res.status(200).json({ address });
78-
79-
}catch(err){
80-
return res.status(500).json({msg: 'Internal Server Error', err})
78+
} catch (err) {
79+
return res.status(500).json({ msg: 'Internal Server Error', err });
8180
}
8281
}
8382
return res.status(400).json({ msg: 'Bad Request: Wallet Id field is must' });
@@ -108,8 +107,6 @@ const AddressController = () => {
108107
};
109108

110109

111-
112-
113110
return {
114111
getAddress,
115112
};

api/controllers/Transactions.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ const Transactions = () => {
8484
await getTrx(req.params.transactionsID);
8585
// Send for notifications
8686
console.log(transactionsData);
87-
} catch (err){
87+
} catch (err) {
8888
console.log(err);
8989
}
9090
}
91-
}
91+
};
9292

9393

9494
const getTransaction = async (req, res) => {
@@ -132,8 +132,6 @@ const Transactions = () => {
132132
};
133133

134134

135-
136-
137135
const getUtxos = async (address) => {
138136
await client.listUnspent(0, 9999999, [address], 2).then((resp) => {
139137
utxos = resp;
@@ -173,7 +171,7 @@ const Transactions = () => {
173171
return {
174172
createTransaction,
175173
getTransaction,
176-
recieveTransactionsUpdate
174+
recieveTransactionsUpdate,
177175
};
178176
};
179177

api/models/Transactions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ const Transactions = sequelize.define('Transactions', {
2525
category: {
2626
type: Sequelize.STRING,
2727
},
28-
timestamp:{
28+
timestamp: {
2929
type: Sequelize.DATE,
3030
},
3131
trxId: {
3232
type: Sequelize.STRING,
33-
}
33+
},
3434

3535
}, { tableName });
3636

config/routes/publicRoutes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const publicRoutes = {
99
'GET /address': 'AddressController.getAddress',
1010
'POST /send': 'Transactions.createTransaction',
1111
'GET /backup/status': 'WalletController.getBackupStatus',
12-
'GET /transactions/:transactionsID' : 'Transactions.recieveTransactionsUpdate'
12+
'GET /transactions/:transactionsID': 'Transactions.recieveTransactionsUpdate',
1313
};
1414

1515
module.exports = publicRoutes;

package-lock.json

Lines changed: 40 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/Open-crypto-API/API/issues"
1313
},
1414
"scripts": {
15-
"prestart":"npm run drop-sqlite-db || true",
15+
"prestart": "npm run drop-sqlite-db || true",
1616
"start": "npm run nodemon",
1717
"poststart": "npm run create-sqlite-db",
1818
"dev": "cross-env NODE_ENV=development node ./api/api.js",

0 commit comments

Comments
 (0)