Evan Feenstra
4 years ago
committed by
GitHub
18 changed files with 447 additions and 6 deletions
@ -1 +1 @@ |
|||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE;QACf,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;KACrB;IACD,gBAAgB,EAAE;QAChB,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACf;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,CAAC;QACb,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;KACb;IACD,aAAa,EAAE;QACb,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;KACd;IACD,aAAa,EAAE;QACb,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,iBAAiB,EAAE,CAAC;QACpB,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,EAAE;QACjB,0BAA0B,EAAE,EAAE;QAC9B,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE;QACpB,eAAe,EAAE,EAAE;QACnB,cAAc,EAAE,EAAE;QAClB,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,wBAAwB,EAAE,EAAE;QAC5B,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ;IACD,aAAa,EAAE;QACb,WAAW,EAAE,CAAC;QACd,MAAM,EAAE,CAAC;KACV;IACD,cAAc,EAAE;QACd,SAAS,EAAE,WAAW;QACtB,UAAU,EAAE,sBAAsB;QAClC,OAAO,EAAE,OAAO;QAChB,2BAA2B,EAAE,2BAA2B;QACxD,SAAS,EAAE,SAAS;KACrB;IACD,UAAU,EAAE;QACV,cAAc,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;KACZ;IACD,UAAU,EAAE;QACV,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;KACZ;CACF,CAAA;AAED,kBAAe,SAAS,CAAA"} |
|||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE;QACf,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;KACrB;IACD,gBAAgB,EAAE;QAChB,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACf;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,C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rB;IACD,UAAU,EAAE;QACV,cAAc,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;KACZ;IACD,UAAU,EAAE;QACV,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;KACZ;CACF,CAAA;AAED,kBAAe,SAAS,CAAA"} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,139 @@ |
|||
"use strict"; |
|||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
|||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
|||
return new (P || (P = Promise))(function (resolve, reject) { |
|||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
|||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
|||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
|||
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
|||
}); |
|||
}; |
|||
Object.defineProperty(exports, "__esModule", { value: true }); |
|||
const res_1 = require("../utils/res"); |
|||
const models_1 = require("../models"); |
|||
const network = require("../network"); |
|||
const constants_1 = require("../constants"); |
|||
const short = require("short-uuid"); |
|||
const lightning = require("../utils/lightning"); |
|||
let queries = {}; |
|||
const hub_pubkey = '023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f'; |
|||
function queryOnchainAddress(req, res) { |
|||
return __awaiter(this, void 0, void 0, function* () { |
|||
console.log('=> queryOnchainAddress'); |
|||
const uuid = short.generate(); |
|||
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); |
|||
const app = req.params.app; |
|||
const query = { |
|||
type: 'onchain_address', |
|||
uuid, |
|||
app |
|||
}; |
|||
const opts = { |
|||
amt: constants_1.default.min_sat_amount, |
|||
dest: hub_pubkey, |
|||
data: { |
|||
type: constants_1.default.message_types.query, |
|||
message: { |
|||
content: JSON.stringify(query) |
|||
}, |
|||
sender: { pub_key: owner.publicKey } |
|||
} |
|||
}; |
|||
try { |
|||
yield network.signAndSend(opts); |
|||
} |
|||
catch (e) { |
|||
res_1.failure(res, e); |
|||
return; |
|||
} |
|||
let i = 0; |
|||
let interval = setInterval(() => { |
|||
if (i >= 15) { |
|||
clearInterval(interval); |
|||
delete queries[uuid]; |
|||
res_1.failure(res, 'no response received'); |
|||
return; |
|||
} |
|||
if (queries[uuid]) { |
|||
res_1.success(res, queries[uuid].result); |
|||
clearInterval(interval); |
|||
delete queries[uuid]; |
|||
return; |
|||
} |
|||
i++; |
|||
}, 1000); |
|||
}); |
|||
} |
|||
exports.queryOnchainAddress = queryOnchainAddress; |
|||
exports.receiveQuery = (payload) => __awaiter(void 0, void 0, void 0, function* () { |
|||
const dat = payload.content || payload; |
|||
const sender_pub_key = dat.sender.pub_key; |
|||
const content = dat.message.content; |
|||
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); |
|||
if (!sender_pub_key || !content || !owner) { |
|||
return console.log('=> wrong query format'); |
|||
} |
|||
let q; |
|||
try { |
|||
q = JSON.parse(content); |
|||
} |
|||
catch (e) { |
|||
console.log("=> ERROR receiveQuery,", e); |
|||
return; |
|||
} |
|||
console.log('=> query received', q); |
|||
let result = ''; |
|||
switch (q.type) { |
|||
case 'onchain_address': |
|||
const addy = yield lightning.newAddress(lightning.NESTED_PUBKEY_HASH); |
|||
const acc = { |
|||
date: new Date(), |
|||
pubkey: sender_pub_key, |
|||
onchainAddress: addy, |
|||
amount: 0, |
|||
sourceApp: q.app, |
|||
status: constants_1.default.statuses.pending, |
|||
error: '', |
|||
}; |
|||
yield models_1.models.Accounting.create(acc); |
|||
result = addy; |
|||
} |
|||
const ret = { |
|||
type: q.type, |
|||
uuid: q.uuid, |
|||
app: q.app, |
|||
result, |
|||
}; |
|||
const opts = { |
|||
amt: constants_1.default.min_sat_amount, |
|||
dest: sender_pub_key, |
|||
data: { |
|||
type: constants_1.default.message_types.query_response, |
|||
message: { |
|||
content: JSON.stringify(ret) |
|||
}, |
|||
sender: { pub_key: owner.publicKey } |
|||
} |
|||
}; |
|||
try { |
|||
yield network.signAndSend(opts); |
|||
} |
|||
catch (e) { |
|||
console.log("FAILED TO SEND QUERY_RESPONSE"); |
|||
return; |
|||
} |
|||
}); |
|||
exports.receiveQueryResponse = (payload) => __awaiter(void 0, void 0, void 0, function* () { |
|||
console.log('=> receiveQueryResponse'); |
|||
const dat = payload.content || payload; |
|||
// const sender_pub_key = dat.sender.pub_key
|
|||
const content = dat.message.content; |
|||
try { |
|||
const q = JSON.parse(content); |
|||
queries[q.uuid] = q; |
|||
} |
|||
catch (e) { |
|||
console.log("=> ERROR receiveQueryResponse,", e); |
|||
} |
|||
}); |
|||
//# sourceMappingURL=queries.js.map
|
@ -0,0 +1 @@ |
|||
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/controllers/queries.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAA+C;AAC/C,sCAAkC;AAClC,sCAAqC;AACrC,4CAAoC;AACpC,oCAAmC;AACnC,gDAA+C;AAU/C,IAAI,OAAO,GAA2B,EAAE,CAAA;AAExC,MAAM,UAAU,GAAG,oEAAoE,CAAA;AAEvF,SAAsB,mBAAmB,CAAC,GAAG,EAAE,GAAG;;QAChD,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;QACrC,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAA;QAC9B,MAAM,KAAK,GAAG,MAAM,eAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;QACxE,MAAM,GAAG,GAAG,GAAG,CAAC,MAA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,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAE7E,MAAM,SAAS,GAAG,IAAI,gCAAS,iCAC1B,MAAM,KACT,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAC7D,MAAM,EAAE,CAAC,cAAI,EAAE,iBAAO,EAAE,gBAAM,EAAE,iBAAO,EAAE,sBAAY,EAAE,kBAAQ,EAAE,oBAAU,EAAE,eAAK,EAAE,aAAG,EAAE,iBAAO,EAAE,mBAAS,EAAE,oBAAU,CAAC,IACxH,CAAA;AAIA,8BAAS;AAHX,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;AAI7B,wBAAM"} |
@ -0,0 +1,60 @@ |
|||
"use strict"; |
|||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
|||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
|||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
|||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
|||
return c > 3 && r && Object.defineProperty(target, key, r), r; |
|||
}; |
|||
var __metadata = (this && this.__metadata) || function (k, v) { |
|||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); |
|||
}; |
|||
Object.defineProperty(exports, "__esModule", { value: true }); |
|||
const sequelize_typescript_1 = require("sequelize-typescript"); |
|||
let Accounting = class Accounting extends sequelize_typescript_1.Model { |
|||
}; |
|||
__decorate([ |
|||
sequelize_typescript_1.Column({ |
|||
type: sequelize_typescript_1.DataType.BIGINT, |
|||
primaryKey: true, |
|||
unique: true, |
|||
autoIncrement: true |
|||
}), |
|||
__metadata("design:type", Number) |
|||
], Accounting.prototype, "id", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column, |
|||
__metadata("design:type", Date) |
|||
], Accounting.prototype, "date", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column, |
|||
__metadata("design:type", String) |
|||
], Accounting.prototype, "pubkey", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column, |
|||
__metadata("design:type", String) |
|||
], Accounting.prototype, "onchainAddress", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.DECIMAL), |
|||
__metadata("design:type", Number) |
|||
], Accounting.prototype, "amount", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column, |
|||
__metadata("design:type", String) |
|||
], Accounting.prototype, "sourceApp", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT), |
|||
__metadata("design:type", Number) |
|||
], Accounting.prototype, "status", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column, |
|||
__metadata("design:type", String) |
|||
], Accounting.prototype, "error", void 0); |
|||
__decorate([ |
|||
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT), |
|||
__metadata("design:type", Number) |
|||
], Accounting.prototype, "chanId", void 0); |
|||
Accounting = __decorate([ |
|||
sequelize_typescript_1.Table({ tableName: 'sphinx_accountings', underscored: true }) |
|||
], Accounting); |
|||
exports.default = Accounting; |
|||
//# sourceMappingURL=accounting.js.map
|
@ -0,0 +1 @@ |
|||
{"version":3,"file":"accounting.js","sourceRoot":"","sources":["../../../../src/models/ts/accounting.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,4BAAiB;CAkCxD,CAAA;AA1BC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;sCACQ;AAGV;IADC,6BAAM;8BACD,IAAI;wCAAA;AAGV;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;kDACe;AAGtB;IADC,6BAAM,CAAC,+BAAQ,CAAC,OAAO,CAAC;;0CACX;AAGd;IADC,6BAAM;;6CACU;AAGjB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACV;AAGd;IADC,6BAAM;;yCACM;AAGb;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACV;AAhCK,UAAU;IAD9B,4BAAK,CAAC,EAAE,SAAS,EAAE,oBAAoB,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;GACzC,UAAU,CAkC9B;kBAlCoB,UAAU"} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,137 @@ |
|||
import { success, failure } from '../utils/res' |
|||
import { models } from '../models' |
|||
import * as network from '../network' |
|||
import constants from '../constants' |
|||
import * as short from 'short-uuid' |
|||
import * as lightning from '../utils/lightning' |
|||
|
|||
type QueryType = 'onchain_address' |
|||
export interface Query { |
|||
type: QueryType |
|||
uuid: string |
|||
result?: string |
|||
app: string |
|||
} |
|||
|
|||
let queries: { [k: string]: Query } = {} |
|||
|
|||
const hub_pubkey = '023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f' |
|||
|
|||
export async function queryOnchainAddress(req, res) { |
|||
console.log('=> queryOnchainAddress') |
|||
const uuid = short.generate() |
|||
const owner = await models.Contact.findOne({ where: { isOwner: true } }) |
|||
const app = req.params.app; |
|||
|
|||
const query:Query = { |
|||
type:'onchain_address', |
|||
uuid, |
|||
app |
|||
} |
|||
|
|||
const opts = { |
|||
amt: constants.min_sat_amount, |
|||
dest: hub_pubkey, |
|||
data: <network.Msg>{ |
|||
type: constants.message_types.query, |
|||
message: { |
|||
content: JSON.stringify(query) |
|||
}, |
|||
sender: { pub_key: owner.publicKey } |
|||
} |
|||
} |
|||
try { |
|||
await network.signAndSend(opts) |
|||
} catch (e) { |
|||
failure(res, e) |
|||
return |
|||
} |
|||
|
|||
let i = 0 |
|||
let interval = setInterval(() => { |
|||
if (i >= 15) { |
|||
clearInterval(interval) |
|||
delete queries[uuid] |
|||
failure(res, 'no response received') |
|||
return |
|||
} |
|||
if (queries[uuid]) { |
|||
success(res, queries[uuid].result) |
|||
clearInterval(interval) |
|||
delete queries[uuid] |
|||
return |
|||
} |
|||
i++ |
|||
}, 1000) |
|||
} |
|||
|
|||
export const receiveQuery = async (payload) => { |
|||
const dat = payload.content || payload |
|||
const sender_pub_key = dat.sender.pub_key |
|||
const content = dat.message.content |
|||
const owner = await models.Contact.findOne({ where: { isOwner: true } }) |
|||
|
|||
if(!sender_pub_key || !content || !owner) { |
|||
return console.log('=> wrong query format') |
|||
} |
|||
let q:Query |
|||
try { |
|||
q = JSON.parse(content) |
|||
} catch(e) { |
|||
console.log("=> ERROR receiveQuery,",e) |
|||
return |
|||
} |
|||
console.log('=> query received', q) |
|||
let result = '' |
|||
switch (q.type) { |
|||
case 'onchain_address': |
|||
const addy = await lightning.newAddress(lightning.NESTED_PUBKEY_HASH) |
|||
const acc = { |
|||
date: new Date(), |
|||
pubkey: sender_pub_key, |
|||
onchainAddress: addy, |
|||
amount: 0, |
|||
sourceApp: q.app, |
|||
status:constants.statuses.pending, |
|||
error:'', |
|||
} |
|||
await models.Accounting.create(acc) |
|||
result = addy |
|||
} |
|||
const ret:Query = { |
|||
type: q.type, |
|||
uuid: q.uuid, |
|||
app: q.app, |
|||
result, |
|||
} |
|||
const opts = { |
|||
amt: constants.min_sat_amount, |
|||
dest: sender_pub_key, |
|||
data: <network.Msg>{ |
|||
type: constants.message_types.query_response, |
|||
message: { |
|||
content: JSON.stringify(ret) |
|||
}, |
|||
sender: { pub_key: owner.publicKey } |
|||
} |
|||
} |
|||
try { |
|||
await network.signAndSend(opts) |
|||
} catch (e) { |
|||
console.log("FAILED TO SEND QUERY_RESPONSE") |
|||
return |
|||
} |
|||
} |
|||
|
|||
export const receiveQueryResponse = async (payload) => { |
|||
console.log('=> receiveQueryResponse') |
|||
const dat = payload.content || payload |
|||
// const sender_pub_key = dat.sender.pub_key
|
|||
const content = dat.message.content |
|||
try { |
|||
const q:Query = JSON.parse(content) |
|||
queries[q.uuid] = q |
|||
} catch(e) { |
|||
console.log("=> ERROR receiveQueryResponse,",e) |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
import { Table, Column, Model, DataType } from 'sequelize-typescript'; |
|||
|
|||
@Table({ tableName: 'sphinx_accountings', underscored: true }) |
|||
export default class Accounting extends Model<Accounting> { |
|||
|
|||
@Column({ |
|||
type: DataType.BIGINT, |
|||
primaryKey: true, |
|||
unique: true, |
|||
autoIncrement: true |
|||
}) |
|||
id: number |
|||
|
|||
@Column |
|||
date: Date |
|||
|
|||
@Column |
|||
pubkey: string |
|||
|
|||
@Column |
|||
onchainAddress: string |
|||
|
|||
@Column(DataType.DECIMAL) |
|||
amount: number |
|||
|
|||
@Column |
|||
sourceApp: string |
|||
|
|||
@Column(DataType.BIGINT) |
|||
status: number |
|||
|
|||
@Column |
|||
error: string |
|||
|
|||
@Column(DataType.BIGINT) |
|||
chanId: number |
|||
|
|||
} |
Loading…
Reference in new issue