Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/settle taggers #444

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dist/src/controllers/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/controllers/index.js.map

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions dist/src/controllers/taggers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/src/controllers/taggers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion dist/src/models/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/models/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions dist/src/models/sql/taggers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/src/models/sql/taggers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { failure } from '../utils/res'
import * as auth from './auth'
import * as personal from './api/personal'
import * as lsats from './lsats'
import * as taggers from './taggers'
import { Req } from '../types'

export async function set(app) {
Expand Down Expand Up @@ -170,6 +171,8 @@ export async function set(app) {
app.post('/lsats', lsats.saveLsat)
app.put('/lsats/:identifier', lsats.updateLsat)
app.delete('/lsats/:identifier', lsats.deleteLsat)

app.post('/pay_taggers', taggers.payTagger)
}

const msgtypes = constants.message_types
Expand Down
59 changes: 59 additions & 0 deletions src/controllers/taggers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Req } from '../types'
import { Response } from 'express'
import { failure, success } from '../utils/res'
import * as Lightning from '../grpc/lightning'
import { models } from '../models'

export const payTagger = async (
req: Req,
res: Response
): Promise<void | Response> => {
if (!req.owner) return failure(res, 'no owner')
const { amount, pubkey, ref_id, timestamp, type } = req.body

if (!amount && !pubkey && !ref_id && !type) {
return failure(res, 'Invalid data provided')
}

if (
typeof amount !== 'number' &&
typeof pubkey !== 'string' &&
typeof ref_id !== 'string' &&
typeof timestamp !== 'string' &&
typeof type != 'string'
)
return failure(res, 'Invalid data provided')

if (pubkey.length !== 66) {
return failure(res, 'Invalid Public Key')
}
const tenant: number = req.owner.id
try {
await Lightning.keysend({
amt: amount,
dest: pubkey,
})
await models.Tagger.create({
tenant,
amount,
pubkey,
type,
refId: ref_id,
timestamp,
status: 1,
})
return success(res, 'Payment Successful')
} catch (e) {
console.log(e)
await models.Tagger.create({
tenant,
amount,
pubkey,
type,
refId: ref_id,
timestamp,
status: 0,
})
return failure(res, 'An error occured')
}
}
4 changes: 4 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as minimist from 'minimist'
import { loadConfig } from '../utils/config'
import { isProxy } from '../utils/proxy'
import { readFileSync } from 'fs'
import Tagger, { TaggerRecord } from './sql/taggers'

const argv = minimist(process.argv.slice(2))

Expand Down Expand Up @@ -51,6 +52,7 @@ const opts = {
Accounting,
Lsat,
RequestsTransportTokens,
Tagger,
],
}
if (isProxy()) {
Expand Down Expand Up @@ -92,4 +94,6 @@ export {
Lsat,
BotMember,
RequestsTransportTokens,
Tagger,
TaggerRecord,
}
38 changes: 38 additions & 0 deletions src/models/sql/taggers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Table, Column, Model, DataType, AllowNull } from 'sequelize-typescript'

@Table({ tableName: 'sphinx_tagger', underscored: true })
export default class Tagger extends Model<Tagger> {
@Column({
type: DataType.BIGINT,
primaryKey: true,
unique: true,
autoIncrement: true,
})
id: number

@Column
pubkey: string

@Column
tenant: number

@Column
type: string

@Column(DataType.DECIMAL)
amount: number

@Column
refId: string

@Column
status: number

@AllowNull(true)
@Column
timestamp: string
}

export interface TaggerRecord extends Tagger {
dataValues: Tagger
}
2 changes: 1 addition & 1 deletion testing/stack/alice-db.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"development": {
"dialect": "sqlite",
"storage": "/Users/evanfeenstra/code/sphinx/sphinx-stack/relay/db/alice.db"
"storage": "/Users/mac/Desktop/work/sphinx/sphinx-stack/relay/db/alice.db"
}
}
4 changes: 2 additions & 2 deletions testing/stack/alice.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"node_ip": "127.0.0.1",
"lnd_ip": "127.0.0.1",
"lnd_port": "10009",
"tls_location": "/Users/evanfeenstra/code/sphinx/sphinx-stack/lnd/alice/.lnd/tls.cert",
"macaroon_location": "/Users/evanfeenstra/code/sphinx/sphinx-stack/lnd/alice/.lnd/data/chain/bitcoin/regtest/admin.macaroon",
"tls_location": "/Users/mac/Desktop/work/sphinx/sphinx-stack/lnd/alice/.lnd/tls.cert",
"macaroon_location": "/Users/mac/Desktop/work/sphinx/sphinx-stack/lnd/alice/.lnd/data/chain/bitcoin/regtest/admin.macaroon",
"node_http_protocol": "http",
"node_http_port": "3001",
"media_host": "localhost:5555",
Expand Down