erc20_processor 0.5.1

Payment processor for ERC20 tokens
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
use std::{fmt::Debug, path::PathBuf};

use crate::actions::attestation::check::AttestationCheckOptions;
use crate::actions::deposit::close::CloseDepositOptions;
use crate::actions::deposit::create::CreateDepositOptions;
use crate::actions::deposit::details::CheckDepositOptions;
use crate::actions::deposit::terminate::TerminateDepositOptions;
use erc20_payment_lib_extra::{BalanceOptions, GenerateOptions};
use structopt::StructOpt;
use web3::types::Address;

#[derive(StructOpt)]
#[structopt(about = "Payment admin tool - run options")]
pub struct RunOptions {
    #[structopt(
        long = "keep-running",
        help = "Set to keep running when finished processing transactions"
    )]
    pub keep_running: bool,

    #[structopt(
        long = "skip-service-loop",
        help = "Set to not process transactions at all"
    )]
    pub skip_service_loop: bool,

    #[structopt(
        long = "generate-tx-only",
        help = "Do not send or process transactions, only generate stubs"
    )]
    pub generate_tx_only: bool,

    #[structopt(
        long = "skip-multi-contract-check",
        help = "Skip multi contract check when generating txs"
    )]
    pub skip_multi_contract_check: bool,

    #[structopt(long = "http", help = "Enable http server")]
    pub http: bool,

    #[structopt(
        long = "http-threads",
        help = "Number of threads to use for the server",
        default_value = "2"
    )]
    pub http_threads: u64,

    #[structopt(
        long = "http-port",
        help = "Port number of the server",
        default_value = "8080"
    )]
    pub http_port: u16,

    #[structopt(
        long = "http-addr",
        help = "Bind address of the server",
        default_value = "127.0.0.1"
    )]
    pub http_addr: String,

    #[structopt(long = "faucet", help = "Enabled faucet for the server")]
    pub faucet: bool,

    #[structopt(long = "debug", help = "Enabled debug endpoint for the server")]
    pub debug: bool,

    #[structopt(long = "transfers", help = "Enabled transfers endpoint for the server")]
    pub transfers: bool,

    #[structopt(long = "frontend", help = "Enabled frontend serving for the server")]
    pub frontend: bool,

    #[structopt(
        long = "balance-check-loop",
        help = "Run forever in loop (for RPC testing) or active balance monitoring. Set number of desired iterations. 0 means forever."
    )]
    pub balance_check_loop: Option<u64>,
}

#[derive(StructOpt)]
#[structopt(about = "Generate private key options")]
pub struct GenerateKeyOptions {
    #[structopt(short = "n", long = "number-of-keys", default_value = "5")]
    pub number_of_keys: usize,
}

#[derive(StructOpt)]
#[structopt(about = "Get dev eth options if faucet is accessible")]
pub struct GetDevEthOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(long = "address", help = "Address to get funds for")]
    pub address: Option<Address>,

    #[structopt(long = "account-no", help = "Which account to use")]
    pub account_no: Option<usize>,
}

#[allow(dead_code)]
#[derive(StructOpt)]
#[structopt(about = "Mint test token options")]
pub struct MintTestTokensOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(long = "address", help = "Address (has to have private key)")]
    pub address: Option<Address>,

    #[structopt(long = "account-no", help = "Address by index (for convenience)")]
    pub account_no: Option<usize>,
}

#[derive(StructOpt)]
#[structopt(about = "Distribute token (gas) options")]
pub struct DistributeOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(long = "address", help = "Address (has to have private key)")]
    pub address: Option<Address>,

    #[structopt(long = "account-no", help = "Address by index (for convenience)")]
    pub account_no: Option<usize>,

    #[structopt(
        short = "r",
        long = "recipients",
        help = "Recipient (semicolon separated)"
    )]
    pub recipients: String,

    #[structopt(
        short = "a",
        long = "amounts",
        help = "Amounts (decimal, full precision, i.e. 0.01;0.002, separate by semicolon)"
    )]
    pub amounts: String,
}

#[derive(StructOpt)]
#[structopt(about = "Single transfer options")]
pub struct TransferOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(short = "r", long = "recipient", help = "Recipient")]
    pub recipient: String,

    #[structopt(long = "address", help = "Address (has to have private key)")]
    pub address: Option<Address>,

    #[structopt(long = "account-no", help = "Address by index (for convenience)")]
    pub account_no: Option<usize>,

    #[structopt(long = "token", help = "Token", default_value = "glm", possible_values = &["glm", "eth", "matic"])]
    pub token: String,

    #[structopt(long = "all", help = "Transfer all available tokens")]
    pub all: bool,

    #[structopt(
        short = "a",
        long = "amount",
        help = "Amount (decimal, full precision, i.e. 0.01)"
    )]
    pub amount: Option<rust_decimal::Decimal>,

    #[structopt(long = "deposit-id")]
    pub deposit_id: Option<String>,

    #[structopt(
        long = "lock-contract",
        help = "Lock contract address (if not specified, it will be taken from config)"
    )]
    pub lock_contract: Option<Address>,
}

#[derive(StructOpt)]
#[structopt(about = "Import payment list")]
pub struct ImportOptions {
    #[structopt(long = "file", help = "File to import")]
    pub file: String,
    #[structopt(long = "separator", help = "Separator", default_value = "|")]
    pub separator: char,
}

#[derive(Debug, StructOpt)]
#[structopt(about = "Scan blockchain options")]
pub struct ScanBlockchainOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(short = "b", long = "from-block")]
    pub from_block: Option<u64>,

    #[structopt(long = "start-new-scan")]
    pub start_new_scan: bool,

    #[structopt(
        long = "max-block-range",
        help = "Limit how much block to process from start"
    )]
    pub max_block_range: Option<u64>,

    #[structopt(
        long = "blocks-behind",
        help = "How much blocks behind scanner should stop"
    )]
    pub blocks_behind: Option<u64>,

    #[structopt(
        long = "forward-scan-buffer",
        help = "How much blocks behind scanner should stop",
        default_value = "40"
    )]
    pub forward_scan_buffer: u64,

    #[structopt(
        long = "blocks-at-once",
        default_value = "1000",
        help = "Limit how much block to process at once. If too much web3 endpoint can return error"
    )]
    pub blocks_at_once: u64,

    #[structopt(
        long = "scan-interval",
        default_value = "2",
        help = "How often check for newest blocks"
    )]
    pub scan_interval: u64,

    #[structopt(long = "import-balances")]
    pub import_balances: bool,

    #[structopt(short = "a", long = "address")]
    pub sender: Option<String>,

    #[structopt(long = "auto")]
    pub auto: bool,
}

#[derive(StructOpt)]
#[structopt(about = "Check web3 RPC")]
pub struct CheckWeb3RpcOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,
}

#[derive(StructOpt)]
#[structopt(about = "Export history stats")]
pub struct ExportHistoryStatsOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(
        long = "export-sqlite-file",
        help = "Export sqlite db file",
        default_value = "export.sqlite"
    )]
    pub export_sqlite_file: PathBuf,
}

#[derive(StructOpt)]
#[structopt(about = "Payment statistics options")]
pub struct PaymentStatsOptions {
    #[structopt(short = "c", long = "chain-name", default_value = "hoodi")]
    pub chain_name: String,

    #[structopt(
        long = "receiver-count",
        help = "Number of receivers to show",
        default_value = "10"
    )]
    pub show_receiver_count: usize,

    #[structopt(
    long = "order-by",
    help = "Order by",
    default_value = "payment_delay",
    possible_values = &["payment_delay", "token_sent", "fee_paid", "gas_paid"]
    )]
    pub order_by: String,

    #[structopt(
    long = "order-by-dir",
    help = "Order by dir",
    default_value = "desc",
    possible_values = &["asc", "desc"]
    )]
    pub order_by_dir: String,

    #[structopt(long = "from-blockchain", help = "Use data downloaded from blockchain")]
    pub from_blockchain: bool,
}

#[derive(StructOpt)]
#[structopt(about = "Import payment list")]
pub struct DecryptKeyStoreOptions {
    #[structopt(
        short = "f",
        long = "file",
        help = "File to import",
        default_value = "payments.csv"
    )]
    pub file: String,
    #[structopt(short = "p", long = "password", help = "Password")]
    pub password: Option<String>,
}

#[derive(StructOpt)]
#[structopt(about = "Cleanup options")]
pub struct CleanupOptions {
    #[structopt(
        long = "remove-unsent-tx",
        help = "Remove transactions that are not sent to the network This operation is safe"
    )]
    pub remove_unsent_tx: bool,

    #[structopt(
        long = "remove-stuck-tx",
        help = "Remove transaction that is stuck due to wrong nonce. \
    Call it if you are sure that processed transaction is not in the blockchain. \
    This operation is unsafe and may lead to double spending"
    )]
    pub remove_tx_stuck: bool,

    #[structopt(
        long = "remove-tx-unsafe",
        help = "Remove transaction that is processed as it never happened. \
    Call it if you are sure that processed transaction is not in the blockchain. \
    This operation is unsafe and may lead to double spending"
    )]
    pub remove_tx_unsafe: bool,

    #[structopt(long = "chain-id", help = "Chain id to use")]
    pub chain_id: Option<i64>,
}

#[derive(StructOpt)]
#[structopt(about = "Attestation commands")]
pub enum AttestationCommands {
    Check {
        #[structopt(flatten)]
        options: AttestationCheckOptions,
    },
}

#[derive(StructOpt)]
#[structopt(about = "Commands for deposit management")]
pub enum DepositCommands {
    Create {
        #[structopt(flatten)]
        make_deposit_options: CreateDepositOptions,
    },
    Close {
        #[structopt(flatten)]
        close_deposit_options: CloseDepositOptions,
    },
    Terminate {
        #[structopt(flatten)]
        terminate_deposit_options: TerminateDepositOptions,
    },
    Check {
        #[structopt(flatten)]
        check_deposit_options: CheckDepositOptions,
    },
}

#[derive(StructOpt)]
#[structopt(about = "Payment admin tool")]
pub enum PaymentCommands {
    Run {
        #[structopt(flatten)]
        run_options: RunOptions,
    },
    #[structopt(about = "Generate test payments")]
    Generate {
        #[structopt(flatten)]
        generate_options: GenerateOptions,
    },
    GenerateKey {
        #[structopt(flatten)]
        generate_key_options: GenerateKeyOptions,
    },
    CheckRpc {
        #[structopt(flatten)]
        check_web3_rpc_options: CheckWeb3RpcOptions,
    },
    GetDevEth {
        #[structopt(flatten)]
        get_dev_eth_options: GetDevEthOptions,
    },
    MintTestTokens {
        #[structopt(flatten)]
        mint_test_tokens_options: MintTestTokensOptions,
    },
    Attestation {
        #[structopt(flatten)]
        attest: AttestationCommands,
    },
    Deposit {
        #[structopt(flatten)]
        deposit: DepositCommands,
    },
    Transfer {
        #[structopt(flatten)]
        single_transfer_options: TransferOptions,
    },
    Distribute {
        #[structopt(flatten)]
        distribute_options: DistributeOptions,
    },
    Balance {
        #[structopt(flatten)]
        account_balance_options: BalanceOptions,
    },
    ImportPayments {
        #[structopt(flatten)]
        import_options: ImportOptions,
    },
    ScanBlockchain {
        #[structopt(flatten)]
        scan_blockchain_options: ScanBlockchainOptions,
    },
    PaymentStats {
        #[structopt(flatten)]
        payment_stats_options: PaymentStatsOptions,
    },
    ExportHistory {
        #[structopt(flatten)]
        export_history_stats_options: ExportHistoryStatsOptions,
    },
    DecryptKeyStore {
        #[structopt(flatten)]
        decrypt_options: DecryptKeyStoreOptions,
    },
    Cleanup {
        #[structopt(flatten)]
        cleanup_options: CleanupOptions,
    },
    ShowConfig,
}

#[derive(StructOpt)]
#[structopt(about = "Payment admin tool")]
pub struct PaymentOptions {
    #[structopt(
        long = "sqlite-db-file",
        help = "Sqlite database file",
        default_value = "./erc20lib.sqlite"
    )]
    pub sqlite_db_file: PathBuf,

    #[structopt(long = "sqlite-read-only", help = "Create read only connection")]
    pub sqlite_read_only: bool,

    #[structopt(long = "skip-migrations", help = "Enable writing to sqlite database")]
    pub skip_migrations: bool,

    #[structopt(
    long = "sqlite-journal",
    help = "SQL journal mode",
    default_value = "delete",
    possible_values = &["delete", "truncate", "persist", "memory", "wal", "off"])]
    pub sqlite_journal: String,

    #[structopt(subcommand)]
    pub commands: PaymentCommands,
}

#[derive(Debug, StructOpt)]
pub struct CliOptions {}