Skip to content

Commit

Permalink
Add parrot analytics library
Browse files Browse the repository at this point in the history
  • Loading branch information
dleutenegger committed Nov 9, 2023
1 parent 2a0885d commit 2335eba
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 34 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ members = [
"graphql",
"honey-badger",
"mole",
"parrot",
]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ and always returns the latest state of them when requested.
## Crow
Crows are known for their love to collect stuff.
The library allows to register for and list withdraw collect offers (e.g. Lightning Address).

## Parrot
This feathered companion, similar to its namesakes, repeats what he hears and as such delivers,
important analytics data about payments to the backend. This data is pseudonymized and used to improve our services.
4 changes: 4 additions & 0 deletions graphql/schemas/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ query MigrationBalance($nodePubKey: String) {
mutation MigrateFunds($invoice: String, $base16InvoiceSignature: String, $ldkNodePubKey: String) {
migrate_funds(invoice: $invoice, base16InvoiceSignature: $base16InvoiceSignature, ldkNodePubKey: $ldkNodePubKey)
}

mutation ReportPaymentTelemetry($telemetryId: String!, $events: PaymentTelemetryEventsInput) {
report_payment_telemetry(telemetryId: $telemetryId, events: $events)
}
116 changes: 84 additions & 32 deletions graphql/schemas/schema_wallet_read.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,79 @@ type MigrationBalanceResponse {
balanceAmountSat: BigInteger!
}

input PayFailedInput {
failedAt: DateTime!
paymentHash: String!
reason: PayFailureReason!
}

enum PayFailureReason {
NO_ROUTE
UNKNOWN
}

input PayInitiatedInput {
executedAt: DateTime!
paidAmountMSat: BigInteger!
paymentHash: String!
processStartedAt: DateTime!
requestedAmountMSat: BigInteger!
satsPerUserCurrency: Int!
source: PaySource!
userCurrency: String!
}

enum PaySource {
CAMERA
CLIPBOARD
MANUAL
NFC
}

input PaySucceededInput {
confirmedAt: DateTime!
lnFeesPaidMSat: BigInteger!
paymentHash: String!
}

input PaymentTelemetryEventsInput {
payFailed: PayFailedInput
payInitiated: PayInitiatedInput
paySucceeded: PaySucceededInput
requestInitiated: RequestInitiatedInput
requestSucceeded: RequestSucceededInput
}

type RegisterTopupResponse {
email: String
nodePubKey: String!
walletPubKeyId: String!
}

type ReportPaymentTelemetryResponse {
payFailed: String
payInitiated: String
paySucceeded: String
requestInitiated: String
requestSucceeded: String
}

input RequestInitiatedInput {
createdAt: DateTime!
enteredAmountMSat: BigInteger!
paymentHash: String!
requestCurrency: String!
satsPerUserCurrency: Int!
userCurrency: String!
}

input RequestSucceededInput {
channelOpeningFeeMSat: BigInteger!
paidAmountMSat: BigInteger!
paymentHash: String!
paymentReceivedAt: DateTime!
}

type SessionPermit {
accessToken: String
refreshToken: String
Expand Down Expand Up @@ -732,23 +799,6 @@ enum cursor_ordering {
DESC
}

scalar float8

"""
Boolean expression to compare columns of type "float8". All fields are combined with logical 'AND'.
"""
input float8_comparison_exp {
_eq: float8
_gt: float8
_gte: float8
_in: [float8!]
_is_null: Boolean
_lt: float8
_lte: float8
_neq: float8
_nin: [float8!]
}

"""mutation root"""
type mutation_root {
"""
Expand Down Expand Up @@ -901,6 +951,7 @@ type mutation_root {
register_node(nodePubKey: String): WalletNode
register_notification_token(language: String!, notificationToken: String!): Token
register_topup(email: String, orderId: String!): RegisterTopupResponse
report_payment_telemetry(events: PaymentTelemetryEventsInput, telemetryId: String!): ReportPaymentTelemetryResponse
start_prepared_session(challenge: String!, challengeSignature: String!, challengeSignatureType: ChallengeSignatureType, preparedPermissionToken: String!): TokenContainer
start_prepared_session_v2(challenge: String!, challengeSignature: String!, challengeSignatureType: ChallengeSignatureType, preparedPermissionToken: String!): SessionPermit
start_session(authPubKey: String!, challenge: String!, challengeSignature: String!, challengeSignatureType: ChallengeSignatureType, signedAuthPubKey: String!, walletPubKey: String!): TokenContainer
Expand Down Expand Up @@ -1063,6 +1114,7 @@ type query_root {
): currency
migration_balance(nodePubKey: String): MigrationBalanceResponse
notification_service_version: String
payment_service_version: String
prepare_wallet_session(challenge: String!, ownerPubKeyId: String!, signature: String!): String

"""
Expand Down Expand Up @@ -1540,14 +1592,14 @@ columns and relationships of "topup"
type topup {
additionalInfo: String
amountSat: bigint!
amountUserCurrency: float8!
amountUserCurrency: numeric!
createdAt: timestamptz!
exchangeFeeRate: float8!
exchangeFeeUserCurrency: float8!
exchangeRate: float8!
exchangeFeeRate: numeric!
exchangeFeeUserCurrency: numeric!
exchangeRate: numeric!
expiresAt: timestamptz
id: uuid!
lightningFeeUserCurrency: float8!
lightningFeeUserCurrency: numeric!
lnurl: String
nodePubKey: String!
status: topup_status_enum!
Expand All @@ -1563,14 +1615,14 @@ input topup_bool_exp {
_or: [topup_bool_exp!]
additionalInfo: String_comparison_exp
amountSat: bigint_comparison_exp
amountUserCurrency: float8_comparison_exp
amountUserCurrency: numeric_comparison_exp
createdAt: timestamptz_comparison_exp
exchangeFeeRate: float8_comparison_exp
exchangeFeeUserCurrency: float8_comparison_exp
exchangeRate: float8_comparison_exp
exchangeFeeRate: numeric_comparison_exp
exchangeFeeUserCurrency: numeric_comparison_exp
exchangeRate: numeric_comparison_exp
expiresAt: timestamptz_comparison_exp
id: uuid_comparison_exp
lightningFeeUserCurrency: float8_comparison_exp
lightningFeeUserCurrency: numeric_comparison_exp
lnurl: String_comparison_exp
nodePubKey: String_comparison_exp
status: topup_status_enum_comparison_exp
Expand Down Expand Up @@ -1676,14 +1728,14 @@ input topup_stream_cursor_input {
input topup_stream_cursor_value_input {
additionalInfo: String
amountSat: bigint
amountUserCurrency: float8
amountUserCurrency: numeric
createdAt: timestamptz
exchangeFeeRate: float8
exchangeFeeUserCurrency: float8
exchangeRate: float8
exchangeFeeRate: numeric
exchangeFeeUserCurrency: numeric
exchangeRate: numeric
expiresAt: timestamptz
id: uuid
lightningFeeUserCurrency: float8
lightningFeeUserCurrency: numeric
lnurl: String
nodePubKey: String
status: topup_status_enum
Expand Down
12 changes: 12 additions & 0 deletions graphql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub use crate::errors::*;
pub use perro;
pub use reqwest;

use chrono::{DateTime, Utc};
use graphql_client::reqwest::post_graphql_blocking;
use graphql_client::Response;
use perro::{permanent_failure, runtime_error, MapToError, OptionToError};
Expand Down Expand Up @@ -159,3 +160,14 @@ mod tests {
assert_eq!(timestamp, 1695314361 + 2 * 3600);
}
}

pub trait ToRfc3339 {
fn to_rfc3339(&self) -> String;
}

impl ToRfc3339 for SystemTime {
fn to_rfc3339(&self) -> String {
let datetime: DateTime<Utc> = DateTime::from(*self);
datetime.to_rfc3339()
}
}
12 changes: 10 additions & 2 deletions graphql/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type numeric = u32;
#[allow(non_camel_case_types)]
type timestamptz = String;
#[allow(non_camel_case_types)]
type DateTime = String;
#[allow(non_camel_case_types)]
type uuid = String;

#[derive(GraphQLQuery)]
Expand Down Expand Up @@ -164,8 +166,6 @@ pub struct GetLatestChannelManager;
#[allow(non_camel_case_types)]
type bigint = u64;
type BigInteger = bigint;
#[allow(non_camel_case_types)]
type float8 = f64;

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -190,3 +190,11 @@ pub struct MigrationBalance;
response_derives = "Debug"
)]
pub struct MigrateFunds;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schemas/schema_wallet_read.graphql",
query_path = "schemas/operations.graphql",
response_derives = "Debug"
)]
pub struct ReportPaymentTelemetry;
13 changes: 13 additions & 0 deletions parrot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "parrot"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.17"

graphql = { path = "../graphql" }
honey-badger = { path = "../honey-badger" }

[dev-dependencies]
simplelog = { version ="0.12.0", features = ["test"] }
Loading

0 comments on commit 2335eba

Please sign in to comment.