Merge pull request #637 from snake-eaterr/userOperation-and-bolt11

User operation and bolt11
This commit is contained in:
Justin (shocknet) 2024-02-06 09:06:22 -05:00 committed by GitHub
commit e671fce443
9 changed files with 3493 additions and 3455 deletions

View file

@ -444,18 +444,19 @@ The nostr server will send back a message response, and inside the body there wi
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### DecodeInvoiceRequest ### AppMetrics
- __invoice__: _string_ - __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_
- __total_received__: _number_
- __total_spent__: _number_
- __total_available__: _number_
- __unpaid_invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### ChannelBalanceEvent ### ClosedChannel
- __block_height__: _number_
- __channel_id__: _string_ - __channel_id__: _string_
- __local_balance_sats__: _number_ - __capacity__: _number_
- __remote_balance_sats__: _number_ - __closed_height__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### GetUserOperationsRequest ### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_ - __latestIncomingInvoice__: _number_
@ -465,6 +466,104 @@ The nostr server will send back a message response, and inside the body there wi
- __latestIncomingUserToUserPayment__: _number_ - __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_ - __latestOutgoingUserToUserPayment__: _number_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### DecodeInvoiceRequest
- __invoice__: _string_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### LndNodeMetrics
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __pending_channels__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
- __user_identifier__: _string_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### GetAppUserRequest
- __user_identifier__: _string_
### UserOperation ### UserOperation
- __paidAtUnix__: _number_ - __paidAtUnix__: _number_
- __type__: _[UserOperationType](#UserOperationType)_ - __type__: _[UserOperationType](#UserOperationType)_
@ -475,59 +574,48 @@ The nostr server will send back a message response, and inside the body there wi
- __service_fee__: _number_ - __service_fee__: _number_
- __network_fee__: _number_ - __network_fee__: _number_
- __confirmed__: _boolean_ - __confirmed__: _boolean_
- __tx_hash__: _string_
- __internal__: _boolean_
### NewAddressRequest ### Empty
- __addressType__: _[AddressType](#AddressType)_
### OpenChannelRequest ### LndMetricsRequest
- __destination__: _string_ - __from_unix__: _number_ *this field is optional
- __fundingAmount__: _number_ - __to_unix__: _number_ *this field is optional
- __pushAmount__: _number_
- __closeAddress__: _string_ ### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### DecodeInvoiceResponse
- __amount__: _number_
### OpenChannelResponse ### OpenChannelResponse
- __channelId__: _string_ - __channelId__: _string_
### RelaysMigration
- __relays__: ARRAY of: _string_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### GetAppUserLNURLInfoRequest ### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
- __base_url_override__: _string_ - __base_url_override__: _string_
### LndGetInfoRequest ### PayAddressRequest
- __nodeId__: _number_ - __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### AuthAppRequest ### PayAppUserInvoiceRequest
- __name__: _string_ - __user_identifier__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### SetMockAppBalanceRequest
- __amount__: _number_
### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### ChainBalanceEvent ### NewInvoiceRequest
- __block_height__: _number_ - __amountSats__: _number_
- __confirmed_balance__: _number_ - __memo__: _string_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### LnurlPayInfoResponse ### LnurlPayInfoResponse
- __tag__: _string_ - __tag__: _string_
@ -538,127 +626,13 @@ The nostr server will send back a message response, and inside the body there wi
- __allowsNostr__: _boolean_ - __allowsNostr__: _boolean_
- __nostrPubkey__: _string_ - __nostrPubkey__: _string_
### SendAppUserToAppUserPaymentRequest ### GetUserOperationsResponse
- __from_user_identifier__: _string_ - __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __to_user_identifier__: _string_ - __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __amount__: _number_ - __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
### OpenChannel - __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __channel_id__: _string_ - __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### AppMetrics
- __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_
- __total_received__: _number_
- __total_spent__: _number_
- __total_available__: _number_
- __unpaid_invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### NewAddressResponse
- __address__: _string_
### GetProductBuyLinkResponse
- __link__: _string_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
- __user_identifier__: _string_
### AddProductRequest
- __name__: _string_
- __price_sats__: _number_
### DecodeInvoiceResponse
- __amount__: _number_
### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### ClosedChannel
- __channel_id__: _string_
- __capacity__: _number_
- __closed_height__: _number_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### GetAppUserRequest
- __user_identifier__: _string_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### LndGetInfoResponse
- __alias__: _string_
### LnurlWithdrawInfoResponse
- __tag__: _string_
- __callback__: _string_
- __k1__: _string_
- __defaultDescription__: _string_
- __minWithdrawable__: _number_
- __maxWithdrawable__: _number_
- __balanceCheck__: _string_
- __payLink__: _string_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### Empty
### RoutingEvent ### RoutingEvent
- __incoming_channel_id__: _number_ - __incoming_channel_id__: _number_
@ -674,18 +648,17 @@ The nostr server will send back a message response, and inside the body there wi
- __offchain__: _boolean_ - __offchain__: _boolean_
- __forward_fail_event__: _boolean_ - __forward_fail_event__: _boolean_
### AddAppInvoiceRequest ### LndGetInfoRequest
- __payer_identifier__: _string_ - __nodeId__: _number_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### NewInvoiceResponse ### AddAppUserRequest
- __invoice__: _string_ - __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### Product ### EncryptionExchangeRequest
- __id__: _string_ - __publicKey__: _string_
- __name__: _string_ - __deviceId__: _string_
- __price_sats__: _number_
### UsageMetric ### UsageMetric
- __processed_at_ms__: _number_ - __processed_at_ms__: _number_
@ -698,42 +671,87 @@ The nostr server will send back a message response, and inside the body there wi
- __nostr__: _boolean_ - __nostr__: _boolean_
- __batch_size__: _number_ - __batch_size__: _number_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### LiveUserOperation ### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_ - __operation__: _[UserOperation](#UserOperation)_
### ClosureMigration ### GetProductBuyLinkResponse
- __closes_at_unix__: _number_ - __link__: _string_
### RelaysMigration ### ChainBalanceEvent
- __relays__: ARRAY of: _string_ - __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### LndNodeMetrics ### SendAppUserToAppUserPaymentRequest
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_ - __from_user_identifier__: _string_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_ - __to_user_identifier__: _string_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_ - __amount__: _number_
- __offline_channels__: _number_
- __online_channels__: _number_ ### SetMockAppBalanceRequest
- __pending_channels__: _number_ - __amount__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_ ### AddProductRequest
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_ - __name__: _string_
- __price_sats__: _number_
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_
### LnurlWithdrawInfoResponse
- __tag__: _string_
- __callback__: _string_
- __k1__: _string_
- __defaultDescription__: _string_
- __minWithdrawable__: _number_
- __maxWithdrawable__: _number_
- __balanceCheck__: _string_
- __payLink__: _string_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### OpenChannelRequest
- __destination__: _string_
- __fundingAmount__: _number_
- __pushAmount__: _number_
- __closeAddress__: _string_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### NewAddressResponse
- __address__: _string_
### PayInvoiceRequest
- __invoice__: _string_
- __amount__: _number_
### LndMetrics
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### LndGetInfoResponse
- __alias__: _string_
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### PayAddressResponse ### PayAddressResponse
- __txId__: _string_ - __txId__: _string_
@ -741,27 +759,11 @@ The nostr server will send back a message response, and inside the body there wi
- __service_fee__: _number_ - __service_fee__: _number_
- __network_fee__: _number_ - __network_fee__: _number_
### LndMetrics ### NewInvoiceResponse
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_
### PayAddressRequest ### ClosureMigration
- __address__: _string_ - __closes_at_unix__: _number_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
## Enums ## Enums
### The enumerators used in the messages ### The enumerators used in the messages

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -348,6 +348,8 @@ message UserOperation {
int64 service_fee = 7; int64 service_fee = 7;
int64 network_fee = 8; int64 network_fee = 8;
bool confirmed = 9; bool confirmed = 9;
string tx_hash = 10;
bool internal = 11;
} }
message UserOperations { message UserOperations {
int64 fromIndex=1; int64 fromIndex=1;

View file

@ -1,14 +1,14 @@
import { OpenChannelRequest, Invoice } from "../../../proto/lnd/lightning"; import { OpenChannelRequest, Invoice } from "../../../proto/lnd/lightning";
export const AddInvoiceReq = (value: number, descriptionHash = Buffer.alloc(0), expiry = 60 * 60, privateHints = false): Invoice => ({ export const AddInvoiceReq = (value: number, expiry = 60 * 60, privateHints = false, memo?: string): Invoice => ({
expiry: BigInt(expiry), expiry: BigInt(expiry),
memo: "", memo: memo || "",
private: privateHints, private: privateHints,
value: BigInt(value), value: BigInt(value),
fallbackAddr: "", fallbackAddr: "",
cltvExpiry: 0n, cltvExpiry: 0n,
descriptionHash, descriptionHash: Buffer.alloc(0),
features: {}, features: {},
isAmp: false, isAmp: false,
rPreimage: Buffer.alloc(0), rPreimage: Buffer.alloc(0),

View file

@ -225,10 +225,7 @@ export default class {
async NewInvoice(value: number, memo: string, expiry: number): Promise<Invoice> { async NewInvoice(value: number, memo: string, expiry: number): Promise<Invoice> {
await this.Health() await this.Health()
const encoder = new TextEncoder() const res = await this.lightning.addInvoice(AddInvoiceReq(value, expiry, false, memo), DeadLineMetadata())
const ecoded = encoder.encode(memo)
const hashed = crypto.createHash('sha256').update(ecoded).digest();
const res = await this.lightning.addInvoice(AddInvoiceReq(value, hashed, expiry), DeadLineMetadata())
return { payRequest: res.response.paymentRequest } return { payRequest: res.response.paymentRequest }
} }

View file

@ -99,7 +99,7 @@ export default class {
await this.storage.paymentStorage.UpdateAddressReceivingTransaction(serialId, { confs: c.confs }) await this.storage.paymentStorage.UpdateAddressReceivingTransaction(serialId, { confs: c.confs })
await this.storage.userStorage.IncrementUserBalance(userAddress.user.user_id, amount - serviceFee) await this.storage.userStorage.IncrementUserBalance(userAddress.user.user_id, amount - serviceFee)
const operationId = `${Types.UserOperationType.INCOMING_TX}-${userAddress.serial_id}` const operationId = `${Types.UserOperationType.INCOMING_TX}-${userAddress.serial_id}`
const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address, operationId, network_fee: 0, service_fee: serviceFee, confirmed: true } const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address, operationId, network_fee: 0, service_fee: serviceFee, confirmed: true, tx_hash: c.tx.tx_hash, internal: c.tx.internal }
this.sendOperationToNostr(userAddress.linkedApplication!, userAddress.user.user_id, op) this.sendOperationToNostr(userAddress.linkedApplication!, userAddress.user.user_id, op)
} }
})) }))
@ -126,7 +126,7 @@ export default class {
const addedTx = await this.storage.paymentStorage.AddAddressReceivingTransaction(userAddress, txOutput.hash, txOutput.index, amount, fee, internal, blockHeight, tx) const addedTx = await this.storage.paymentStorage.AddAddressReceivingTransaction(userAddress, txOutput.hash, txOutput.index, amount, fee, internal, blockHeight, tx)
await this.storage.userStorage.IncrementUserBalance(userAddress.user.user_id, addedTx.paid_amount - fee, tx) await this.storage.userStorage.IncrementUserBalance(userAddress.user.user_id, addedTx.paid_amount - fee, tx)
const operationId = `${Types.UserOperationType.INCOMING_TX}-${userAddress.serial_id}` const operationId = `${Types.UserOperationType.INCOMING_TX}-${userAddress.serial_id}`
const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address, operationId, network_fee: 0, service_fee: fee, confirmed: internal } const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address, operationId, network_fee: 0, service_fee: fee, confirmed: internal, tx_hash: txOutput.hash, internal: false }
this.sendOperationToNostr(userAddress.linkedApplication, userAddress.user.user_id, op) this.sendOperationToNostr(userAddress.linkedApplication, userAddress.user.user_id, op)
} catch { } catch {
@ -161,7 +161,7 @@ export default class {
await this.triggerPaidCallback(log, userInvoice.callbackUrl) await this.triggerPaidCallback(log, userInvoice.callbackUrl)
const operationId = `${Types.UserOperationType.INCOMING_INVOICE}-${userInvoice.serial_id}` const operationId = `${Types.UserOperationType.INCOMING_INVOICE}-${userInvoice.serial_id}`
const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_INVOICE, identifier: userInvoice.invoice, operationId, network_fee: 0, service_fee: fee, confirmed: true } const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_INVOICE, identifier: userInvoice.invoice, operationId, network_fee: 0, service_fee: fee, confirmed: true, tx_hash: "", internal }
this.sendOperationToNostr(userInvoice.linkedApplication, userInvoice.user.user_id, op) this.sendOperationToNostr(userInvoice.linkedApplication, userInvoice.user.user_id, op)
this.createZapReceipt(log, userInvoice) this.createZapReceipt(log, userInvoice)
log("paid invoice processed successfully") log("paid invoice processed successfully")

View file

@ -27,6 +27,11 @@ interface UserOperationInfo {
routing_fees?: number routing_fees?: number
chain_fees?: number chain_fees?: number
confs?: number confs?: number
tx_hash?: string;
user_address?: {
address: string
};
internal?: boolean;
} }
export type PendingTx = { type: 'incoming', tx: AddressReceivingTransaction } | { type: 'outgoing', tx: UserTransactionPayment } export type PendingTx = { type: 'incoming', tx: AddressReceivingTransaction } | { type: 'outgoing', tx: UserTransactionPayment }
const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]` const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]`
@ -416,11 +421,13 @@ export default class {
toIndex: operations[0].serial_id, toIndex: operations[0].serial_id,
fromIndex: operations[operations.length - 1].serial_id, fromIndex: operations[operations.length - 1].serial_id,
operations: operations.map((o: UserOperationInfo): Types.UserOperation => { operations: operations.map((o: UserOperationInfo): Types.UserOperation => {
let identifier = "" let identifier = "";
if (o.invoice) { if (o.invoice) {
identifier = o.invoice identifier = o.invoice
} else if (o.address) { } else if (o.address) {
identifier = o.address identifier = o.address;
} else if(o.user_address) {
identifier = o.user_address.address;
} else if (type === Types.UserOperationType.INCOMING_USER_TO_USER && o.from_user) { } else if (type === Types.UserOperationType.INCOMING_USER_TO_USER && o.from_user) {
identifier = o.from_user.user_id identifier = o.from_user.user_id
} else if (type === Types.UserOperationType.OUTGOING_INVOICE && o.to_user) { } else if (type === Types.UserOperationType.OUTGOING_INVOICE && o.to_user) {
@ -435,7 +442,9 @@ export default class {
operationId: `${type}-${o.serial_id}`, operationId: `${type}-${o.serial_id}`,
network_fee: o.chain_fees || o.routing_fees || 0, network_fee: o.chain_fees || o.routing_fees || 0,
service_fee: o.service_fee || o.service_fees || 0, service_fee: o.service_fee || o.service_fees || 0,
confirmed: typeof o.confs === 'number' ? o.confs > 0 : true confirmed: typeof o.confs === 'number' ? o.confs > 0 : true,
tx_hash: o.tx_hash || "",
internal: !!o.internal
} }
}) })
} }

View file

@ -103,30 +103,30 @@ export default class Handler {
receivingInvoices.forEach(i => { receivingInvoices.forEach(i => {
if (i.paid_at_unix > 0) { if (i.paid_at_unix > 0) {
totalReceived += i.paid_amount totalReceived += i.paid_amount
if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_INVOICE, amount: i.paid_amount, inbound: true, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fee, network_fee: 0, identifier: "", operationId: "" }) if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_INVOICE, amount: i.paid_amount, inbound: true, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fee, network_fee: 0, identifier: "", operationId: "", tx_hash: "", internal: i.internal })
} else { } else {
unpaidInvoices++ unpaidInvoices++
} }
}) })
receivingTransactions.forEach(txs => { receivingTransactions.forEach(txs => {
txs.forEach(tx => { txs.forEach(tx => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_TX, amount: tx.paid_amount, inbound: true, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fee, network_fee: 0, identifier: "", operationId: "" }) if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_TX, amount: tx.paid_amount, inbound: true, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fee, network_fee: 0, identifier: "", operationId: "", tx_hash: tx.tx_hash, internal: tx.internal })
if (tx.confs > 1) { if (tx.confs > 1) {
totalReceived += tx.paid_amount totalReceived += tx.paid_amount
} }
}) })
}) })
outgoingInvoices.forEach(i => { outgoingInvoices.forEach(i => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_INVOICE, amount: i.paid_amount, inbound: false, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fees, network_fee: i.routing_fees, identifier: "", operationId: "" }) if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_INVOICE, amount: i.paid_amount, inbound: false, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fees, network_fee: i.routing_fees, identifier: "", operationId: "", tx_hash: "", internal: i.internal })
totalSpent += i.paid_amount totalSpent += i.paid_amount
}) })
outgoingTransactions.forEach(tx => { outgoingTransactions.forEach(tx => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_TX, amount: tx.paid_amount, inbound: false, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fees, network_fee: tx.chain_fees, identifier: "", operationId: "" }) if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_TX, amount: tx.paid_amount, inbound: false, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fees, network_fee: tx.chain_fees, identifier: "", operationId: "", tx_hash: tx.tx_hash, internal: tx.internal })
totalSpent += tx.paid_amount totalSpent += tx.paid_amount
}) })
userToUser.forEach(op => { userToUser.forEach(op => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_USER_TO_USER, amount: op.paid_amount, inbound: true, paidAtUnix: op.paid_at_unix, confirmed: true, service_fee: op.service_fees, network_fee: 0, identifier: "", operationId: "" }) if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_USER_TO_USER, amount: op.paid_amount, inbound: true, paidAtUnix: op.paid_at_unix, confirmed: true, service_fee: op.service_fees, network_fee: 0, identifier: "", operationId: "", tx_hash: "", internal: true })
}) })
const users = await this.storage.applicationStorage.GetApplicationUsers(app, { from: req.from_unix, to: req.to_unix }) const users = await this.storage.applicationStorage.GetApplicationUsers(app, { from: req.from_unix, to: req.to_unix })