Class: VChainClient::BlockchainConnection
- Inherits:
-
Object
- Object
- VChainClient::BlockchainConnection
- Defined in:
- lib/vchain_client/blockchain_connection.rb
Instance Method Summary collapse
- #getTx(txid) ⇒ Object
-
#initialize(config) ⇒ BlockchainConnection
constructor
A new instance of BlockchainConnection.
Constructor Details
#initialize(config) ⇒ BlockchainConnection
Returns a new instance of BlockchainConnection.
9 10 11 12 13 |
# File 'lib/vchain_client/blockchain_connection.rb', line 9 def initialize(config) @config = config @log = Log4r::Logger["vchain_client"] end |
Instance Method Details
#getTx(txid) ⇒ Object
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 |
# File 'lib/vchain_client/blockchain_connection.rb', line 15 def getTx(txid) if @log.debug? @log.debug("[BlockchainConnection.getTx] input:") @log.debug("-> txid: #{txid}") end adapters = [] if !@config.key?("blockchain_adapters") raise "There are no blockchain_adapters in config" end config_adapters = @config["blockchain_adapters"] if config_adapters.length <= 0 raise "There are no blockchain_adapters in config" end config_adapters.each { |adapter_config| begin adapter = VChainClient::BlockchainAdapterFactory.getAdapter(adapter_config["type"], adapter_config, @config) rescue => e if @log.error? @log.error("[BlockchainConnection.getTx] BlockchainAdapterFactory.getAdapter raised exception:") @log.error("#{e.class}, #{e.message}") @log.error("-> txid: #{txid}") @log.error("--> type: "+ adapter_config["type"]) end raise e end if adapter != nil adapters.push(adapter) else if @log.error? @log.error("[BlockchainConnection.getTx] failed to init BlockchainAdapter") @log.error("-> txid: #{txid}") @log.error("--> type: "+ adapter_config["type"]) end end } if adapters.length > 0 prev_size = nil prev_block_hash = nil = nil prev_op_return = nil adapters.each { |adapter| tx = nil begin tx = adapter.getTx(txid) rescue => e if @log.error? @log.error("[BlockchainConnection.getTx] adapter.getTx raised exception:") @log.error("#{e.class}, #{e.message}") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end raise e end if tx == nil if @log.error? @log.error("[BlockchainConnection.getTx] failed to get tx") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end if !tx.key?("block_hash") if @log.error? @log.error("[BlockchainConnection.getTx] no 'block_hash' field") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end if !tx.key?("block_timestamp") if @log.error? @log.error("[BlockchainConnection.getTx] no 'block_timestamp' field") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end if tx["block_hash"] == nil || tx["block_hash"] == "" if @log.error? @log.error("[BlockchainConnection.getTx] 'block_hash' field is empty") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end size = tx["size"] block_hash = tx["block_hash"] = tx["block_timestamp"] op_return = tx["op_return"] if prev_size != nil && prev_size != size if @log.error? @log.error("[BlockchainConnection.getTx] size mismatch") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end if prev_block_hash != nil && prev_block_hash != block_hash if @log.error? @log.error("[BlockchainConnection.getTx] block_hash mismatch") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end if != nil && != if @log.error? @log.error("[BlockchainConnection.getTx] block_timestamp mismatch") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end if prev_op_return != nil && prev_op_return != op_return if @log.error? @log.error("[BlockchainConnection.getTx] op_return mismatch") @log.error("-> txid: #{txid}") @log.error("--> txid: #{txid}") @log.error("--> adapter: "+ adapter.getName()) end return nil end prev_size = size prev_block_hash = block_hash = prev_op_return = op_return } return { "block_hash" => prev_block_hash, "block_timestamp" => , "op_return" => prev_op_return } else raise "There are no initialized blockchain_adapters" end return nil end |