tezos_client 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/tezos_client/tools/convert_to_hash.rb +68 -56
- data/lib/tezos_client/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: df136ec49d2d790db5cee86eb542be4c0a0ffbc08cd32da8b45ed24f3b30faac
         | 
| 4 | 
            +
              data.tar.gz: 245b8ca7495bd975cd20e41fcec00968ff436d80c2cbdfebdd47f95618323c67
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1ef0f079eb71e4fa9e2716130d7cbd06f33abd93a8dfdf14c9b388730fe0289b21d8d4b4424b2f246c8dfd3079af5b16e4438b3a22bab8ce0c564f8f5794e11f
         | 
| 7 | 
            +
              data.tar.gz: 90b9ef025edacccf89275c4f5ec6be72511f182705f6b224fb756f05259fdd940e480fc4b4368d674122858f0da2195c200a77585750a77c0ef3e0b7c2f02114
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -5,83 +5,95 @@ class TezosClient::Tools::ConvertToHash < ActiveInteraction::Base | |
| 5 5 | 
             
              interface :type
         | 
| 6 6 |  | 
| 7 7 | 
             
              def execute
         | 
| 8 | 
            +
                decorated_value
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              private
         | 
| 12 | 
            +
              def value
         | 
| 8 13 | 
             
                case type[:prim]
         | 
| 9 14 | 
             
                when "pair"
         | 
| 10 | 
            -
                  pair_type | 
| 15 | 
            +
                  pair_type
         | 
| 11 16 | 
             
                when "list"
         | 
| 12 | 
            -
                  list_type | 
| 17 | 
            +
                  list_type
         | 
| 13 18 | 
             
                when "int"
         | 
| 14 | 
            -
                  int_type | 
| 19 | 
            +
                  int_type
         | 
| 15 20 | 
             
                when "nat"
         | 
| 16 | 
            -
                  int_type | 
| 21 | 
            +
                  int_type
         | 
| 17 22 | 
             
                when "key"
         | 
| 18 | 
            -
                  key_type | 
| 23 | 
            +
                  key_type
         | 
| 19 24 | 
             
                when "timestamp"
         | 
| 20 | 
            -
                  timestamp_type | 
| 25 | 
            +
                  timestamp_type
         | 
| 21 26 | 
             
                when "string"
         | 
| 22 | 
            -
                  string_type | 
| 27 | 
            +
                  string_type
         | 
| 23 28 | 
             
                when "address"
         | 
| 24 | 
            -
                  address_type | 
| 29 | 
            +
                  address_type
         | 
| 25 30 | 
             
                else
         | 
| 26 31 | 
             
                  raise "type '#{type[:prim]}' not implemented"
         | 
| 27 32 | 
             
                end
         | 
| 28 33 | 
             
              end
         | 
| 29 34 |  | 
| 30 | 
            -
               | 
| 31 | 
            -
                 | 
| 32 | 
            -
             | 
| 33 | 
            -
                  raise "Difference detected between data and type \nDATA: #{data} \nTYPE:#{type} " unless data[:args].size == type[:args].size
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  result = {}
         | 
| 36 | 
            -
                  data[:args].size.times do |iter|
         | 
| 37 | 
            -
                    result.merge!(
         | 
| 38 | 
            -
                      compose(
         | 
| 39 | 
            -
                        TezosClient::Tools::ConvertToHash,
         | 
| 40 | 
            -
                        data: data[:args][iter],
         | 
| 41 | 
            -
                        type: type[:args][iter]
         | 
| 42 | 
            -
                      )
         | 
| 43 | 
            -
                    )
         | 
| 44 | 
            -
                  end
         | 
| 45 | 
            -
                  result
         | 
| 46 | 
            -
                end
         | 
| 35 | 
            +
              def pair_type
         | 
| 36 | 
            +
                raise "Not a 'Pair' type" unless data[:prim] == "Pair"
         | 
| 37 | 
            +
                raise "Difference detected between data and type \nDATA: #{data} \nTYPE:#{type} " unless data[:args].size == type[:args].size
         | 
| 47 38 |  | 
| 48 | 
            -
                 | 
| 49 | 
            -
                   | 
| 50 | 
            -
                     | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 39 | 
            +
                (data[:args]).zip(type[:args]).map do |data_n, type_n|
         | 
| 40 | 
            +
                  compose(
         | 
| 41 | 
            +
                    TezosClient::Tools::ConvertToHash,
         | 
| 42 | 
            +
                    data: data_n,
         | 
| 43 | 
            +
                    type: type_n
         | 
| 44 | 
            +
                  )
         | 
| 45 | 
            +
                end.reduce({}, &:merge)
         | 
| 46 | 
            +
              end
         | 
| 53 47 |  | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
                      TezosClient::Tools::ConvertToHash,
         | 
| 58 | 
            -
                      data: elem,
         | 
| 59 | 
            -
                      type: element_type
         | 
| 60 | 
            -
                    )
         | 
| 61 | 
            -
                  end
         | 
| 62 | 
            -
                end
         | 
| 48 | 
            +
              def list_type
         | 
| 49 | 
            +
                convert_list_element(data: data, element_type: type[:args].first)
         | 
| 50 | 
            +
              end
         | 
| 63 51 |  | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 52 | 
            +
              def convert_list_element(data:, element_type:)
         | 
| 53 | 
            +
                data.map do |elem|
         | 
| 54 | 
            +
                  compose(
         | 
| 55 | 
            +
                    TezosClient::Tools::ConvertToHash,
         | 
| 56 | 
            +
                    data: elem,
         | 
| 57 | 
            +
                    type: element_type
         | 
| 58 | 
            +
                  )
         | 
| 66 59 | 
             
                end
         | 
| 60 | 
            +
              end
         | 
| 67 61 |  | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 62 | 
            +
              def int_type
         | 
| 63 | 
            +
                data[:int].to_i
         | 
| 64 | 
            +
              end
         | 
| 71 65 |  | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 66 | 
            +
              def key_type
         | 
| 67 | 
            +
                data[:bytes] || data[:string]
         | 
| 68 | 
            +
              end
         | 
| 75 69 |  | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 70 | 
            +
              def timestamp_type
         | 
| 71 | 
            +
                Time.zone.at(data[:int].to_i)
         | 
| 72 | 
            +
              end
         | 
| 79 73 |  | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 74 | 
            +
              def string_type
         | 
| 75 | 
            +
                data[:string]
         | 
| 76 | 
            +
              end
         | 
| 83 77 |  | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 78 | 
            +
              def address_type
         | 
| 79 | 
            +
                data[:bytes] || data[:string]
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              def decorated_value
         | 
| 83 | 
            +
                anonymous? ? value : { var_name => value }
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              def anonymous?
         | 
| 87 | 
            +
                !(type.key?(:annots) && type[:annots].any?)
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              def var_name_annot
         | 
| 91 | 
            +
                type[:annots].first
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              def var_name
         | 
| 95 | 
            +
                return nil if anonymous?
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                "#{var_name_annot[1..-1]}".to_sym
         | 
| 98 | 
            +
              end
         | 
| 87 99 | 
             
            end
         | 
    
        data/lib/tezos_client/version.rb
    CHANGED