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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
use chrono::{DateTime, Utc, Duration};
use serde::{Serialize, Deserialize};
use crate::errors::Result;
use libabieos_sys::ABIEOS;
/*
pub(crate) mod eosio_action_trace {
    use serde::{self, Serializer, Deserializer};
    use serde_json:: Value;
    use std::collections::HashMap;

    pub fn serialize<S>(
        _string: &str,
        _serializer: S,
    ) -> Result<S::Ok, S::Error>
        where
            S: Serializer,
    {
        panic!("Deserialize only");
        //  serializer.serialize_str(&s)
    }

    pub fn deserialize<'de, D>(
        deserializer: D,
    ) -> Result<HashMap<String, Value>, D::Error>
        where
            D: Deserializer<'de>,
    {

        // let s: String = String::deserialize(deserializer)?;
        let m: HashMap<String, Value> = HashMap::new();
        Ok(m)
    }
}
*/
pub(crate) mod eosio_datetime_format {
    use chrono::{DateTime, Utc, TimeZone, NaiveDateTime};
    use serde::{self, Deserialize, Serializer, Deserializer};

    const FORMAT: &str = "%Y-%m-%dT%H:%M:%S";

    // The signature of a serialize_with function must follow the pattern:
    //
    //    fn serialize<S>(&T, S) -> Result<S::Ok, S::Error>
    //    where
    //        S: Serializer
    //
    // although it may also be generic over the input types T.
    pub fn serialize<S>(
        date: &DateTime<Utc>,
        serializer: S,
    ) -> Result<S::Ok, S::Error>
        where
            S: Serializer,
    {
        let s = format!("{}", date.format(FORMAT));
        serializer.serialize_str(&s)
    }

    // The signature of a deserialize_with function must follow the pattern:
    //
    //    fn deserialize<'de, D>(D) -> Result<T, D::Error>
    //    where
    //        D: Deserializer<'de>
    //
    // although it may also be generic over the output types T.
    pub fn deserialize<'de, D>(
        deserializer: D,
    ) -> Result<DateTime<Utc>, D::Error>
        where
            D: Deserializer<'de>,
    {
        let s: String = String::deserialize(deserializer)?;
        let len = s.len();
        let slice_len = if s.contains('.') {
            len.saturating_sub(4)
        } else {
            len
        };

        // match Utc.datetime_from_str(&s, FORMAT) {
        let sliced = &s[0..slice_len];
        match NaiveDateTime::parse_from_str(sliced, FORMAT) {
            Err(_e) => {
                eprintln!("DateTime Fail {} {:#?}", sliced, _e);
                Err(serde::de::Error::custom(_e))
            }
            Ok(dt) => Ok(Utc.from_utc_datetime(&dt)),
        }
    }
}

fn byte_to_char(x: u8) -> char {
    (if x <= 9 {
        x + b'0'
    } else {
        x - 10 + b'a'
    }) as char
}


pub fn vec_u8_to_hex(out: &[u8]) -> Result<String> {
    let mut str = String::with_capacity(out.len());
    for x in out {
        str.push(byte_to_char((x & 0xf0).checked_shr(4).unwrap_or(0)));
        str.push(byte_to_char(x & 0x0f));
    }
    Ok(str)
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ResourceLimit {
    max: isize,
    available: isize,
    used: isize,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Key {
    key: String,
    weight: isize,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Permission {
    permission: String,
    actor: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Account {
    weight: isize,
    permission: Permission,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RequiredAuth {
    waits: Vec<String>,
    threshold: isize,
    accounts: Vec<Account>,
    keys: Vec<Key>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Permissions {
    parent: String,
    perm_name: String,
    required_auth: RequiredAuth,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct VoterInfo {
    producers: Vec<String>,
    is_proxy: isize,
    owner: String,
    // staked: usize, Wax holds this as a string, EOS is a usize
    proxy: String,
    flags1: isize,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetAccount {
    account_name: String,
    head_block_num: usize,
    privileged: bool,
    #[serde(with = "eosio_datetime_format")]
    last_code_update: DateTime<Utc>,
    #[serde(with = "eosio_datetime_format")]
    head_block_time: DateTime<Utc>,
    #[serde(with = "eosio_datetime_format")]
    created: DateTime<Utc>,
    core_liquid_balance: Option<String>,
    ram_quota: isize,
    net_weight: isize,
    cpu_weight: isize,
    ram_usage: usize,
    cpu_limit: ResourceLimit,
    net_limit: ResourceLimit,
    voter_info: Option<VoterInfo>,
    refund_request: Option<String>,
    permissions: Vec<Permissions>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiTypes {
    new_type_name: String,
    #[serde(rename = "type")]
    abi_type: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiField {
    name: String,
    #[serde(rename = "type")]
    abi_type: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiStruct {
    name: String,
    base: String,
    fields: Vec<AbiField>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiAction {
    name: String,
    #[serde(rename = "type")]
    abi_type: String,
    ricardian_contract: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiTable {
    name: String,
    #[serde(rename = "type")]
    abi_type: String,
    index_type: String,
    key_names: Vec<String>,
    key_types: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiRicardianClauses {
    id: String,
    body: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiErrorMessages {
    error_code: String,
    error_msg: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiExtensions {
    tag: String,
    value: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbiVariants {
    name: String,
    typea: Vec<String>,
}


#[derive(Debug, Serialize, Deserialize)]
pub struct Abi {
    version: String,
    types: Vec<AbiTypes>,
    structs: Vec<AbiStruct>,
    actions: Vec<AbiAction>,
    tables: Vec<AbiTable>,
    ricardian_clauses: Vec<AbiRicardianClauses>,
    error_messages: Vec<AbiErrorMessages>,
    abi_extensions: Vec<AbiExtensions>,
    variants: Vec<AbiVariants>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetAbi {
    account_name: String,
    abi: Abi,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RequiredKeys {
    pub required_keys: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetInfo {
    server_version: String,
    pub chain_id: String,
    pub head_block_num: usize,
    pub last_irreversible_block_num: usize,
    pub last_irreversible_block_id: String,
    pub head_block_id: String,
    #[serde(with = "eosio_datetime_format")]
    pub head_block_time: DateTime<Utc>,
    head_block_producer: String,
    virtual_block_cpu_limit: usize,
    virtual_block_net_limit: usize,
    block_cpu_limit: usize,
    block_net_limit: usize,
    server_version_string: String,
    fork_db_head_block_num: usize,
    fork_db_head_block_id: String,
    server_full_version_string: Option<String>,
}

impl GetInfo {
    pub fn set_exp_time(&self, duration: Duration) -> DateTime<Utc> {
        self.head_block_time + duration
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AuthorizationIn {
    pub actor: String,
    pub permission: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetCodeHash {
    pub account_name: String,
    pub code_hash: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ActionIn {
    pub account: String,
    pub name: String,
    pub authorization: Vec<AuthorizationIn>,
    pub data: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TransactionInSigned {
    #[serde(with = "eosio_datetime_format")]
    expiration: DateTime<Utc>,
    ref_block_num: u16,
    ref_block_prefix: u32,
    max_net_usage_words: u32,
    max_cpu_usage_ms: u8,
    delay_sec: u32,
    context_free_actions: Vec<String>,
    pub actions: Vec<ActionIn>,
    transaction_extensions: Vec<String>,
    pub signatures: Vec<String>, // KleosD 2.1 returns signatures here
}

/***
 Be aware. The ordering of this struct is important.
 EOSIO (abieos) expects the fields in the same order as shown in transaction.abi.json, and does not
 handle extra fields either.

 ref_block_num & ref_block_prefix are derived from the last_irreversible_block_id. retrieved from
 the get_info call.

--> thank you to @arhag for the detailed explanation.

if I use the last_irreversible_block_id from getinfo — (I added the '-' for clarity)
“0000daabcc9912b6-2359def6033b0463-d3a605c0ba7d6c77-9452ed321649db15”
The block ID modifies the hash of the block header such that its first 4 bytes represents the block
height as a big endian number. This is so that when it is printed out as a hex string, one could
just grab the first 8 hex characters to quickly determine what the block height is.

So the block height of that block you reference there is actually 0x0000daab (or 55979 in decimal).

The ref_block_num field of a transaction is the height of the reference block (modulo 2^16).
So in this case it would again be 55979.

The ref_block_prefix field of a transaction is some 32-bits of the reference block ID
(other than the first 4 bytes which represents the height and therefore serves no meaningful
validation purposes) as a simple check to ensure you are referencing the actual block you meant
to reference and not some other block on another fork that has the same block height.

Those are taken from the 2nd 64-bit word of the block ID which is then cast to
uint32_t so it is the least significant 32-bits of the 2nd 64-bit word.

So the 2nd 64-bit word would be taken from the sequence of bytes
(represented in hex): 0x23, 0x59, 0xde, 0xf6, 0x03, 0x3b, 0x04, 0x63.
When pulled as a uint64_t number on a little endian machine, that is the number 0x63043b03f6de5923.
And the least significant 32-bits of that number is 0xf6de5923 which is what ref_block_prefix
should be.

The ref_block_num would be 0x0000daab mod 2^16 which is 0xdaab.

expiration has a max of now + 3600 seconds.
delay_sec should be 0 for normal things. (it's used in deferred txn's which aren't really used).
 */
#[derive(Debug, Serialize, Deserialize)]
pub struct TransactionIn {
    #[serde(with = "eosio_datetime_format")]
    expiration: DateTime<Utc>,
    ref_block_num: u16,
    ref_block_prefix: u32,
    max_net_usage_words: u32,
    max_cpu_usage_ms: u8,
    delay_sec: u32,
    context_free_actions: Vec<String>,
    pub actions: Vec<ActionIn>,
    transaction_extensions: Vec<String>,
}

impl TransactionIn {
    pub fn dummy() -> TransactionIn {
        TransactionIn {
            transaction_extensions: vec![],
            ref_block_num: 0,
            max_net_usage_words: 0,
            expiration: Utc::now() + Duration::days(1),
            delay_sec: 0,
            max_cpu_usage_ms: 0,
            actions: vec![],
            ref_block_prefix: 0,
            context_free_actions: vec![],
        }
    }
    pub fn simple(actions: Vec<ActionIn>, ref_block_id: &str, expiration: DateTime<Utc>) -> Result<TransactionIn> {
        let hash = TransactionIn::block_to_hash(ref_block_id)?;

        let ref_block_num: u16 = (((hash[0] >> 32) & 0xffff_ffff) as u16).to_le();
        let ref_block_prefix: u32 = ((hash[1] >> 32 & 0xffff_ffff) as u32).to_be();

        Ok(TransactionIn {
            transaction_extensions: vec![],
            ref_block_num,
            max_net_usage_words: 0,
            expiration,
            delay_sec: 0,
            max_cpu_usage_ms: 0,
            actions,
            ref_block_prefix,
            context_free_actions: vec![],
        })
    }

    pub fn hex_to_u64(hex: &str) -> u64 {
        let mut val: u64 = 0;
        for char in hex.bytes() {
            let digit = if char >= b'a' {
                char + 10 - b'a'
            } else {
                char - b'0'
            };
            val = (val << 4) + digit as u64;
        }
        val
    }
    pub fn block_to_hash(ref_block_id: &str) -> Result<Vec<u64>> {
        if ref_block_id.len() != 64 {
            Err("Invalid ref_block id. expecting len of 64".into())
        } else {
            let v: Vec<u64> = vec![TransactionIn::hex_to_u64(&ref_block_id[0..16]),
                                   TransactionIn::hex_to_u64(&ref_block_id[16..32]),
                                   TransactionIn::hex_to_u64(&ref_block_id[33..48]),
                                   TransactionIn::hex_to_u64(&ref_block_id[49..64])];
            Ok(v)
        }
    }
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ErrorDetails {
    pub message: String,
    pub file: String,
    pub line_number: usize,
    pub method: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ErrorInt {
    pub code: usize,
    pub name: String,
    pub what: String,
    pub details: Vec<ErrorDetails>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ErrorReply {
    pub code: usize,
    pub message: String,
    pub error: ErrorInt,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PackedTransactionIn {
    pub signatures: Vec<String>,
    pub compression: String,
    pub packed_context_free_data: String,
    pub packed_trx: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetRawABI {
    pub account_name: String,
    pub code_hash: String,
    pub abi_hash: String,
    pub abi: String,
}

impl GetRawABI {
    /*
    EOSIO doesn't seem to pad base64 correctly
    see https://github.com/EOSIO/eos/issues/8161
     */
    fn fix_padding(str: &str) -> String {
        let mut bare: String = str.replacen('=', "", 4);
        let len = bare.len();
        let to_len = len + (4 - (len % 4));
        for _i in len..to_len {
            bare.push('=');
        }
        bare
    }

    pub fn decode_abi(&self) -> Result<Vec<u8>> {
        let fixed = GetRawABI::fix_padding(&self.abi);
        Ok(base64::decode(fixed)?)
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ActionSetcodeData {
    pub(crate) account: String,
    pub(crate) vmtype: u8,
    pub(crate) vmversion: u8,
    pub(crate) code: String,
}


impl ActionSetcodeData {
    pub fn to_hex(&self, abieos: &ABIEOS) -> Result<String> {
        // abieos NEEDS the json to be in a specific order serde_json doesn't do that
        let json = format!("{{ \"account\":\"{}\", \"vmtype\":{},\"vmversion\":{},\"code\":\"{}\" }}",
                           self.account, self.vmtype, self.vmversion, self.code);

        let hex = abieos.json_to_hex("eosio", "setcode", &json)?;
        Ok(String::from(hex))
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ActionSetData {
    pub(crate) account: String,
    pub(crate) abi: String,
}

impl ActionSetData {
    pub fn to_hex(&self, abieos: &ABIEOS) -> Result<String> {
        let json = format!("{{ \"account\":\"{}\", \"abi\":\"{}\"}}", self.account, self.abi);

        let hex = abieos.json_to_hex("eosio", "setabi", &json);
        Ok(String::from(hex?))
    }
}

#[derive(Debug, Deserialize)]
pub struct TransactionResponse {
    pub processed: TransactionProcessedResponse,
    pub transaction_id: String,
}

#[derive(Debug, Deserialize)]
pub struct TransactionReceipt {
    cpu_usage_us: usize,
    net_usage_words: usize,
    status: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AccountRamDelta {
    account: String,
    delta: isize,
}

#[derive(Debug, Deserialize)]
pub struct ActionReceipt {
    receiver: String,
    abi_sequence: usize,
    recv_sequence: usize,
    // auth_sequence: Vec< String|usize>
    code_sequence: usize,
    global_sequence: usize,
    act_digest: String,
}

#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum ActionACTData {
    ActionACTDataSetCode {
        code: Option<String>,
        vmtype: usize,
        account: String,
        vmversion: usize,
    },
    String,
    /*
    ActionACTDataSetABI {
        account: String,
        abi: String,
    }*/
}

#[derive(Debug, Deserialize)]
pub struct ActionACT {
    authorization: Vec<Permission>,
    name: String,

    //  #[serde(with = "eosio_action_trace")]
    // data: HashMap<String,Value>,
    account: String,
    hex_data: String,
}

#[derive(Debug, Deserialize)]
pub struct ActionTrace {
    account_ram_deltas: Vec<AccountRamDelta>,
    console: Option<String>,
    action_ordinal: isize,
    // inline_traces:[],
    receipt: ActionReceipt,
    act: ActionACT,
    context_free: bool,
    producer_block_id: Option<String>,
    except: Option<String>,
    trx_id: String,
    block_num: usize,
    error_code: Option<String>,
    #[serde(with = "eosio_datetime_format")]
    block_time: DateTime<Utc>,
    closest_unnotified_ancestor_action_ordinal: usize,
    elapsed: usize,
    receiver: String,
    //account_disk_deltas : [],
    return_value: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct TransactionProcessedResponse {
    scheduled: bool,
    error_code: Option<String>,
    action_traces: Vec<ActionTrace>,
    pub block_num: usize,
    producer_block_id: Option<String>,
    except: Option<String>,
    pub receipt: TransactionReceipt,
    pub id: String,
    elapsed: usize,
    net_usage: usize,
    #[serde(with = "eosio_datetime_format")]
    block_time: DateTime<Utc>,
    account_ram_delta: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BlockTransactionAction {
    pub account: String,
    pub name: String,
    pub authorization: Vec<AuthorizationIn>,
    pub data: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BlockTransaction {
    #[serde(with = "eosio_datetime_format")]
    expiration: DateTime<Utc>,
    ref_block_num: u16,
    ref_block_prefix: u32,
    max_net_usage_words: u32,
    max_cpu_usage_ms: u8,
    delay_sec: u32,
    context_free_actions: Vec<String>,
    pub actions: Vec<BlockTransactionAction>,
}

#[derive(Debug, Deserialize)]
pub struct BlockTransactionTrx {
    pub id: String,
    signatures: Vec<String>,
    compression: String,
    packed_context_free_data: String,
    // context_free_data: Vec<?>
    packed_trx: String,
    pub transaction: BlockTransaction,

}

#[derive(Debug, Deserialize)]
pub struct BlockTransactions {
    status: String,
    cpu_usage_us: usize,
    net_usage_words: usize,
    pub trx: BlockTransactionTrx,

}

#[derive(Debug, Deserialize)]
pub struct GetBlock {
    #[serde(with = "eosio_datetime_format")]
    timestamp: DateTime<Utc>,
    producer: String,
    confirmed: usize,
    previous: String,
    transaction_mroot: String,
    action_mroot: String,
    schedule_version: usize,
    new_producers: Option<String>,
    producer_signature: String,
    pub transactions: Vec<BlockTransactions>,
    pub id: String,
    pub block_num: usize,
    ref_block_prefix: usize,
}

#[derive(Debug, Deserialize)]
pub struct TableRow {
    pub code: String,
    pub scope: String,
    pub table: String,
    pub payer: String,
    pub count: usize,
}

#[derive(Debug, Deserialize)]
pub struct GetTableByScope {
    pub rows: Vec<TableRow>,
    pub more: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetTableByScopeIn {
    pub code: String,
    pub table: String,
    pub lower_bound: String,
    pub upper_bound: String,
    pub limit: usize,
    pub reverse: bool,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetTableRowsIn {
    pub json: bool, /// set this to false if you are using GetTableRow
    pub code: String,
    pub scope: String,
    pub table: String,
    pub table_key: String,
    pub lower_bound: String,
    pub upper_bound: String,
    pub limit: usize,
    pub key_type: String,
    pub index_position: String,
    pub encode_type: String,
    pub reverse: bool,
    pub show_payer: bool,
}
#[derive(Debug, Deserialize)]
pub struct GetTableRow {
   pub data:String, /// set to json:false in request, returns abieos-packed version
   pub payer:Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct GetTableRows {
    pub rows: Vec<GetTableRow>,
    pub more: bool,
    pub next_key:String,
}