-
Notifications
You must be signed in to change notification settings - Fork 89
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
663/mk/use open payments client #706
Changes from 53 commits
d3470c4
7f968c3
79e7cd7
32e2a31
050ebef
9893029
c15fdbc
130e310
e067011
dc28878
39b561b
9393e47
3c3a0b7
120dcae
80d9856
218f1f0
d7c203c
dfc07cb
d59c2ea
bc0ea85
43335f6
723de2f
02b8f9f
c111b4c
b7e1282
f8c1846
f560c79
e11ec65
0dad54d
000fc9b
25d2617
f734dff
4552188
85db136
dc4aa0f
c927291
3ed946b
347075a
90bc6b0
3129f2a
05b6cfb
f1d2412
f6eb6a8
f18cc2d
9b3de72
3306129
9535ee2
bcda9c8
ad74758
df3bcf4
d950377
eaa4e87
6c65e96
d997e79
9d726d9
2a8cbe9
6ea7205
042c8fd
08c2708
691a95e
581d7f7
acba42e
fbdcb48
e9b41c4
39ebc2b
1bebc31
d277827
d51d3d2
f3558d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { StreamCredentials } from '@interledger/stream-receiver' | ||
import base64url from 'base64url' | ||
import { IlpAddress } from 'ilp-packet' | ||
import { ILPStreamConnection } from 'open-payments' | ||
import { IncomingPayment } from '../payment/incoming/model' | ||
|
||
export type ConnectionJSON = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still needed because of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still used in the connection routes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't necessarily have to happen in this pr, but I think the routes should use generated types from |
||
id: string | ||
ilpAddress: IlpAddress | ||
sharedSecret: string | ||
assetCode: string | ||
assetScale: number | ||
} | ||
|
||
export abstract class ConnectionBase { | ||
protected constructor( | ||
public readonly ilpAddress: IlpAddress, | ||
public readonly sharedSecret: Buffer, | ||
public readonly assetCode: string, | ||
public readonly assetScale: number | ||
) {} | ||
} | ||
|
||
export class Connection extends ConnectionBase { | ||
static fromPayment(options: { | ||
payment: IncomingPayment | ||
credentials: StreamCredentials | ||
openPaymentsUrl: string | ||
}): Connection { | ||
return new this( | ||
options.payment.connectionId, | ||
options.openPaymentsUrl, | ||
options.credentials.ilpAddress, | ||
options.credentials.sharedSecret, | ||
options.payment.asset.code, | ||
options.payment.asset.scale | ||
) | ||
} | ||
|
||
private constructor( | ||
public readonly id: string, | ||
private readonly openPaymentsUrl: string, | ||
ilpAddress: IlpAddress, | ||
sharedSecret: Buffer, | ||
assetCode: string, | ||
assetScale: number | ||
) { | ||
super(ilpAddress, sharedSecret, assetCode, assetScale) | ||
} | ||
|
||
public get url(): string { | ||
return `${this.openPaymentsUrl}/connections/${this.id}` | ||
} | ||
|
||
public toJSON(): ConnectionJSON { | ||
return { | ||
id: this.url, | ||
ilpAddress: this.ilpAddress, | ||
sharedSecret: base64url(this.sharedSecret), | ||
assetCode: this.assetCode, | ||
assetScale: this.assetScale | ||
} | ||
} | ||
|
||
public toOpenPaymentsType(): ILPStreamConnection { | ||
return { | ||
id: this.url, | ||
ilpAddress: this.ilpAddress, | ||
sharedSecret: base64url(this.sharedSecret), | ||
assetCode: this.assetCode, | ||
assetScale: this.assetScale | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,8 @@ | ||
import base64url from 'base64url' | ||
import { IlpAddress } from 'ilp-packet' | ||
import { StreamCredentials, StreamServer } from '@interledger/stream-receiver' | ||
import { StreamServer } from '@interledger/stream-receiver' | ||
|
||
import { BaseService } from '../../shared/baseService' | ||
import { IncomingPayment } from '../payment/incoming/model' | ||
|
||
export type ConnectionJSON = { | ||
id: string | ||
ilpAddress: IlpAddress | ||
sharedSecret: string | ||
assetCode: string | ||
assetScale: number | ||
} | ||
|
||
export abstract class ConnectionBase { | ||
protected constructor( | ||
public readonly ilpAddress: IlpAddress, | ||
public readonly sharedSecret: Buffer, | ||
public readonly assetCode: string, | ||
public readonly assetScale: number | ||
) {} | ||
} | ||
|
||
export class Connection extends ConnectionBase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to its own |
||
static fromPayment(options: { | ||
payment: IncomingPayment | ||
credentials: StreamCredentials | ||
openPaymentsUrl: string | ||
}): Connection { | ||
return new this( | ||
options.payment.connectionId, | ||
options.openPaymentsUrl, | ||
options.credentials.ilpAddress, | ||
options.credentials.sharedSecret, | ||
options.payment.asset.code, | ||
options.payment.asset.scale | ||
) | ||
} | ||
|
||
private constructor( | ||
public readonly id: string, | ||
private readonly openPaymentsUrl: string, | ||
ilpAddress: IlpAddress, | ||
sharedSecret: Buffer, | ||
assetCode: string, | ||
assetScale: number | ||
) { | ||
super(ilpAddress, sharedSecret, assetCode, assetScale) | ||
} | ||
|
||
public get url(): string { | ||
return `${this.openPaymentsUrl}/connections/${this.id}` | ||
} | ||
|
||
public toJSON(): ConnectionJSON { | ||
return { | ||
id: this.url, | ||
ilpAddress: this.ilpAddress, | ||
sharedSecret: base64url(this.sharedSecret), | ||
assetCode: this.assetCode, | ||
assetScale: this.assetScale | ||
} | ||
} | ||
} | ||
import { Connection } from './model' | ||
|
||
export interface ConnectionService { | ||
get(payment: IncomingPayment): Connection | undefined | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Model, ModelOptions, Pojo, QueryContext } from 'objection' | |
import { v4 as uuid } from 'uuid' | ||
|
||
import { Amount, AmountJSON } from '../../amount' | ||
import { ConnectionJSON } from '../../connection/service' | ||
import { Connection, ConnectionJSON } from '../../connection/model' | ||
import { | ||
PaymentPointer, | ||
PaymentPointerSubresource | ||
|
@@ -11,6 +11,7 @@ import { Asset } from '../../../asset/model' | |
import { LiquidityAccount, OnCreditOptions } from '../../../accounting/service' | ||
import { ConnectorAccount } from '../../../connector/core/rafiki' | ||
import { WebhookEvent } from '../../../webhook/model' | ||
import { IncomingPayment as OpenPaymentsIncomingPayment } from 'open-payments' | ||
|
||
export enum IncomingPaymentEventType { | ||
IncomingPaymentExpired = 'incoming_payment.expired', | ||
|
@@ -237,6 +238,30 @@ export class IncomingPayment | |
} | ||
return payment | ||
} | ||
|
||
public toOpenPaymentsType({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect this can replace a number of existing |
||
ilpStreamConnection | ||
}: { | ||
ilpStreamConnection: Connection | ||
}): OpenPaymentsIncomingPayment { | ||
return { | ||
id: this.id, | ||
paymentPointer: this.paymentPointer.url, | ||
incomingAmount: { | ||
...this.incomingAmount, | ||
value: this.incomingAmount.value.toString() | ||
}, | ||
receivedAmount: { | ||
...this.receivedAmount, | ||
value: this.receivedAmount.value.toString() | ||
}, | ||
completed: this.completed, | ||
createdAt: this.createdAt.toISOString(), | ||
updatedAt: this.updatedAt.toISOString(), | ||
expiresAt: this.expiresAt.toISOString(), | ||
ilpStreamConnection: ilpStreamConnection.toOpenPaymentsType() | ||
} | ||
} | ||
} | ||
|
||
// TODO: disallow undefined | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on how #722 shapes up, this might also take
config.privateKey
+ a key id