Browse Source

Merge branch 'master' into feature/docker

feature/dockerfile-arm
Gonzalo Javier Aune 5 years ago
parent
commit
46e07ed85c
  1. 2
      .gitignore
  2. 2
      README.md
  3. 8
      api/controllers/payment.ts
  4. 31
      api/grpc/index.ts
  5. 18
      api/utils/lightning.ts
  6. 2
      config/config.json
  7. 7
      dist/api/controllers/payment.js
  8. 2
      dist/api/controllers/payment.js.map
  9. 28
      dist/api/grpc/index.js
  10. 2
      dist/api/grpc/index.js.map
  11. 20
      dist/api/utils/lightning.js
  12. 2
      dist/api/utils/lightning.js.map
  13. 86
      install_guide_myNode_and_Raspiblitz.md
  14. 2691
      rpc.proto

2
.gitignore

@ -1,6 +1,8 @@
notes.md
todo.md
sphinx.db
# just for testing
binaries/nodeapp-macos
binaries/nodeapp-alpine

2
README.md

@ -76,7 +76,7 @@ You can run your own Sphinx node in order to have full ownership over your commu
### guide
mynode users: here is a complete guide provided by someone who is running Relay at home: [MyNode Guide](https://github.com/stakwork/sphinx-relay/blob/master/install_guide_myNode.md)
mynode users: here is a complete guide provided by someone who is running Relay at home: [MyNode Guide](https://github.com/stakwork/sphinx-relay/blob/master/install_guide_myNode_and_Raspiblitz.md)
### download

8
api/controllers/payment.ts

@ -160,11 +160,13 @@ const listPayments = async (req, res) => {
const payments: any[] = []
const MIN_VAL=3
const invs:any = await lightning.listAllInvoices()
if(invs && invs.length){
invs.forEach(inv=>{
const val = inv.value && parseInt(inv.value)
if(val && val>1) {
if(val && val>MIN_VAL) {
let payment_hash=''
if(inv.r_hash){
payment_hash = Buffer.from(inv.r_hash).toString('hex')
@ -184,12 +186,12 @@ const listPayments = async (req, res) => {
if(pays && pays.length){
pays.forEach(pay=>{
const val = pay.value && parseInt(pay.value)
if(val && val>1) {
if(val && val>MIN_VAL) {
payments.push({
type:'payment',
amount:parseInt(pay.value),
date:parseInt(pay.creation_date),
pubkey:pay.path[pay.path.length-1],
// pubkey:pay.path[pay.path.length-1],
payment_hash: pay.payment_hash,
})
}

31
api/grpc/index.ts

@ -24,9 +24,12 @@ async function parseAndVerifyPayload(data){
payload.sender = payload.sender||{}
payload.sender.pub_key=v.pubkey
return payload
} else {
console.error('[GRPC] invalid payload signature')
}
}
} catch(e) {
console.error('[GRPC] failed to parse msg')
return null
}
}
@ -36,16 +39,27 @@ async function parseKeysendInvoice(i, actions){
const buf = recs && recs[SPHINX_CUSTOM_RECORD_KEY]
const data = buf && buf.toString()
const value = i && i.value && parseInt(i.value)
if(!data) return
if(!data) {
console.error('[GRPC] no keysend data received')
return
}
let payload
if(data[0]==='{'){
try {
payload = await parseAndVerifyPayload(data)
} catch(e){}
} catch(e){
console.error('[GRPC] failed to parse and verify payload')
}
} else {
const threads = weave(data)
if(threads) payload = await parseAndVerifyPayload(threads)
if(threads) {
try {
payload = await parseAndVerifyPayload(threads)
} catch(e){
console.error('[GRPC] failed to parse and verify payload II')
}
}
}
if(payload){
const dat = payload.content || payload
@ -57,6 +71,8 @@ async function parseKeysendInvoice(i, actions){
} else {
console.log('Incorrect payload type:', payload.type)
}
} else {
console.error('[GRPC] no payload')
}
}
@ -85,9 +101,10 @@ function subscribeInvoices(actions) {
return new Promise(async(resolve,reject)=>{
const lightning = await loadLightning()
var call = lightning.subscribeInvoices();
var call = lightning.subscribeInvoices()
call.on('data', async function(response) {
// console.log('subscribed invoices', { response })
console.log('[GRPC] subscribeInvoices received')
if (response['state'] !== 'SETTLED') {
return
}
@ -155,9 +172,9 @@ function subscribeInvoices(actions) {
call.on('status', function(status) {
console.log("Status", status);
resolve(status)
});
})
call.on('error', function(err){
// console.log(err)
console.error(err)
reject(err)
})
call.on('end', function() {
@ -165,7 +182,7 @@ function subscribeInvoices(actions) {
console.log(`Closed stream ${now}`);
// The server has closed the stream.
reconnectToLND()
});
})
setTimeout(()=>{
resolve(null)
},100)

18
api/utils/lightning.ts

@ -254,18 +254,20 @@ function listInvoicesPaginated(limit, offset) {
}
// need to upgrade to .10 for this
async function listAllPaymentsPaginated(){
const invs = await paginatePayments(40) // max num
return invs
async function listAllPayments(){
console.log("=> list all payments")
const pays = await paginatePayments(40) // max num
console.log('pays', pays && pays.length)
return pays
}
async function paginatePayments(limit,i=0){
try{
const r:any = await listPaymentsPaginated(limit,i)
const lastOffset = parseInt(r.first_index_offset) // this is "first" cuz its in reverse (lowest index)
if(lastOffset>0) {
return r.invoices.concat(await paginatePayments(limit,lastOffset))
return r.payments.concat(await paginatePayments(limit,lastOffset))
}
return r.invoices
return r.payments
}catch(e){
return []
}
@ -274,7 +276,7 @@ function listPaymentsPaginated(limit, offset) {
return new Promise(async(resolve, reject)=> {
const lightning = await loadLightning()
lightning.listPayments({
num_max_payments: limit,
max_payments: limit,
index_offset: offset,
reversed: true,
}, (err, response) => {
@ -284,7 +286,7 @@ function listPaymentsPaginated(limit, offset) {
})
}
function listAllPayments() {
function listAllPaymentsFull() {
console.log('=> list all payments')
return new Promise(async(resolve, reject)=> {
const lightning = await loadLightning()
@ -397,5 +399,5 @@ export {
listAllPayments,
checkConnection,
listAllInvoices,
listAllPaymentsPaginated,
listAllPaymentsFull,
}

2
config/config.json

@ -1,7 +1,7 @@
{
"development": {
"dialect": "sqlite",
"storage": "./sphinx.db"
"storage": "/Users/Shared/sphinx.db"
},
"docker_development": {
"dialect": "sqlite",

7
dist/api/controllers/payment.js

@ -146,11 +146,12 @@ const listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function* (
const limit = (req.query.limit && parseInt(req.query.limit)) || 100;
const offset = (req.query.offset && parseInt(req.query.offset)) || 0;
const payments = [];
const MIN_VAL = 3;
const invs = yield lightning.listAllInvoices();
if (invs && invs.length) {
invs.forEach(inv => {
const val = inv.value && parseInt(inv.value);
if (val && val > 1) {
if (val && val > MIN_VAL) {
let payment_hash = '';
if (inv.r_hash) {
payment_hash = Buffer.from(inv.r_hash).toString('hex');
@ -169,12 +170,12 @@ const listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function* (
if (pays && pays.length) {
pays.forEach(pay => {
const val = pay.value && parseInt(pay.value);
if (val && val > 1) {
if (val && val > MIN_VAL) {
payments.push({
type: 'payment',
amount: parseInt(pay.value),
date: parseInt(pay.creation_date),
pubkey: pay.path[pay.path.length - 1],
// pubkey:pay.path[pay.path.length-1],
payment_hash: pay.payment_hash,
});
}

2
dist/api/controllers/payment.js.map

File diff suppressed because one or more lines are too long

28
dist/api/grpc/index.js

@ -35,9 +35,13 @@ function parseAndVerifyPayload(data) {
payload.sender.pub_key = v.pubkey;
return payload;
}
else {
console.error('[GRPC] invalid payload signature');
}
}
}
catch (e) {
console.error('[GRPC] failed to parse msg');
return null;
}
});
@ -48,19 +52,29 @@ function parseKeysendInvoice(i, actions) {
const buf = recs && recs[lightning_1.SPHINX_CUSTOM_RECORD_KEY];
const data = buf && buf.toString();
const value = i && i.value && parseInt(i.value);
if (!data)
if (!data) {
console.error('[GRPC] no keysend data received');
return;
}
let payload;
if (data[0] === '{') {
try {
payload = yield parseAndVerifyPayload(data);
}
catch (e) { }
catch (e) {
console.error('[GRPC] failed to parse and verify payload');
}
}
else {
const threads = weave(data);
if (threads)
payload = yield parseAndVerifyPayload(threads);
if (threads) {
try {
payload = yield parseAndVerifyPayload(threads);
}
catch (e) {
console.error('[GRPC] failed to parse and verify payload II');
}
}
}
if (payload) {
const dat = payload.content || payload;
@ -74,6 +88,9 @@ function parseKeysendInvoice(i, actions) {
console.log('Incorrect payload type:', payload.type);
}
}
else {
console.error('[GRPC] no payload');
}
});
}
const chunks = {};
@ -104,6 +121,7 @@ function subscribeInvoices(actions) {
call.on('data', function (response) {
return __awaiter(this, void 0, void 0, function* () {
// console.log('subscribed invoices', { response })
console.log('[GRPC] subscribeInvoices received');
if (response['state'] !== 'SETTLED') {
return;
}
@ -167,7 +185,7 @@ function subscribeInvoices(actions) {
resolve(status);
});
call.on('error', function (err) {
// console.log(err)
console.error(err);
reject(err);
});
call.on('end', function () {

2
dist/api/grpc/index.js.map

File diff suppressed because one or more lines are too long

20
dist/api/utils/lightning.js

@ -284,22 +284,24 @@ function listInvoicesPaginated(limit, offset) {
}));
}
// need to upgrade to .10 for this
function listAllPaymentsPaginated() {
function listAllPayments() {
return __awaiter(this, void 0, void 0, function* () {
const invs = yield paginatePayments(40); // max num
return invs;
console.log("=> list all payments");
const pays = yield paginatePayments(40); // max num
console.log('pays', pays && pays.length);
return pays;
});
}
exports.listAllPaymentsPaginated = listAllPaymentsPaginated;
exports.listAllPayments = listAllPayments;
function paginatePayments(limit, i = 0) {
return __awaiter(this, void 0, void 0, function* () {
try {
const r = yield listPaymentsPaginated(limit, i);
const lastOffset = parseInt(r.first_index_offset); // this is "first" cuz its in reverse (lowest index)
if (lastOffset > 0) {
return r.invoices.concat(yield paginatePayments(limit, lastOffset));
return r.payments.concat(yield paginatePayments(limit, lastOffset));
}
return r.invoices;
return r.payments;
}
catch (e) {
return [];
@ -310,7 +312,7 @@ function listPaymentsPaginated(limit, offset) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
const lightning = yield loadLightning();
lightning.listPayments({
num_max_payments: limit,
max_payments: limit,
index_offset: offset,
reversed: true,
}, (err, response) => {
@ -321,7 +323,7 @@ function listPaymentsPaginated(limit, offset) {
});
}));
}
function listAllPayments() {
function listAllPaymentsFull() {
console.log('=> list all payments');
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
const lightning = yield loadLightning();
@ -335,7 +337,7 @@ function listAllPayments() {
});
}));
}
exports.listAllPayments = listAllPayments;
exports.listAllPaymentsFull = listAllPaymentsFull;
const signMessage = (msg) => {
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
let lightning = yield loadLightning();

2
dist/api/utils/lightning.js.map

File diff suppressed because one or more lines are too long

86
install_guide_myNode.md → install_guide_myNode_and_Raspiblitz.md

@ -1,4 +1,4 @@
# Guide: install Sphinx-relay on myNode.
# Guide: install Sphinx-relay on myNode / Raspiblitz.
This guide is focused on installing Sphinx-relay on top of myNode. Information about myNode can be found at: https://mynodebtc.com/.
@ -48,6 +48,7 @@ $ npm install
```
### Dependencies
sqlite3: `$ apt-get install sqlite3`
python2: `$ apt-get install python2`
### Configure
Edit the "production" section of config/app.json.
@ -56,13 +57,24 @@ $ cd
$ cd sphinx-relay/config/
$ nano app.json
```
Change the following 4 lines to:
Change the following 4 lines:
## myNode
```
"macaroon_location": "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tls_location": "/mnt/hdd/mynode/lnd/tls.cert",
"lnd_log_location": "/home/bitcoin/.lnd/logs/bitcoin/mainnet/lnd.log",
"lncli_location": "/home/bitcoin/go/bin",
```
## Raspiblitz
```
"macaroon_location": "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tls_location": "/mnt/hdd/lnd/tls.cert",
"lnd_log_location": "/home/bitcoin/.lnd/logs/bitcoin/mainnet/lnd.log",
"lncli_location": "/home/bitcoin/go/bin",
```
Save and exit:
`Ctrl + X`
@ -86,7 +98,7 @@ Save and exit:
`Enter`
To connect to your app:
(replace x.x.x.x with your IP)
(replace x.x.x.x with your IP - NOTE: This is your external IP)
```sh
$ cd
$ cd sphinx-relay/config/
@ -97,10 +109,24 @@ For extra security:
$ export USE_PASSWORD=true
```
### Activate keysend
We need LND to run with keysend activated. First we check if it is already activated on your node. To do that. Go to http://mynode.local/lnd/config and check if the line `accept-keysend=1` is included somewhere in the text.
We need LND to run with keysend activated. First we check if it is already activated on your node.
## myNode:
Go to http://mynode.local/lnd/config and check if the line `accept-keysend=1` is included somewhere in the text.
If `accept-keysend=1` is already included you can continue without changing anything. If `accept-keysend=1` is not included, add it to a new line and click the `Save` button. This will restart your device. (Restarting could take up to several minutes but also hours, so be patient.)
## Raspiblitz:
Go to raspiblitz menu, or:
```sh
$ raspiblitz
```
Find item menu "Services" and activate Keysend
### Run
Now it's time to run the software.
@ -110,3 +136,55 @@ $ cd sphinx-relay/config/
$ npm run prod
```
When Relay starts up, it will print a QR in the terminal. You can scan this in your app (Android or iOS) to connect!
### To make relay run continuously (also after a restart).
Before you start this part. Make sure your app is connected and you are able to send & receive messages.
Login as admin.
```sh
$ sudo su admin
```
Create a file named sphinx-relay.service
```sh
$ sudo nano /etc/systemd/system/sphinx/sphinx-relay.service
```
Copy and paste the following text to add it to the file:
```sh
[Unit]
Description=Sphinx Relay Service
After=network.target
[Service]
Type=simple
User=bitcoin
WorkingDirectory=/home/bitcoin/sphinx-relay/config/
ExecStart=npm run prod
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sphinx-relay
[Install]
WantedBy=multi-user.target
```
Save and exit:
`Ctrl + X`
`Y`
`Enter`
Let's run!
```sh
$ sudo systemctl enable sphinx-relay.service
$ sudo systemctl start sphinx-relay.service
```
Check if relay succesfully started.
```sh
$ sudo systemctl status sphinx-relay.service
```
### To stop the program
```sh
$ sudo systemctl stop sphinx-relay.service
```

2691
rpc.proto

File diff suppressed because it is too large
Loading…
Cancel
Save