class OBC::Connection

Attributes

http[R]
user[R]

Public Class Methods

new(config) click to toggle source
# File lib/openblockchain-ruby.rb, line 26
def initialize(config)
  @http = Net::HTTP.new(config[:api][:host], config[:api][:port])
  @user = config[:enroll]
end

Public Instance Methods

deploy(path, *init_args) click to toggle source
# File lib/openblockchain-ruby.rb, line 10
def deploy(path, *init_args)    # "github.com/openblockchain/obc-peer/openchain/example/chaincode/chaincode_example02", "a", "1000", "b", "2000"
  post('/devops/deploy', deploy_payload(path, *init_args))
end
invoke(chaincode_name, *args) click to toggle source
# File lib/openblockchain-ruby.rb, line 14
def invoke(chaincode_name, *args)
  post('/devops/invoke', invoke_payload(chaincode_name, *args))
end
post_registrar() click to toggle source
# File lib/openblockchain-ruby.rb, line 6
def post_registrar
  post('/registrar', registrar_payload)
end
query(chaincode_name, *args) click to toggle source
# File lib/openblockchain-ruby.rb, line 18
def query(chaincode_name, *args)
  post('/devops/query', query_payload(chaincode_name, *args))
end

Private Instance Methods

deploy_payload(path, *init_args) click to toggle source
# File lib/openblockchain-ruby.rb, line 44
def deploy_payload(path, *init_args)
  {
    type: "GOLANG",
    chaincodeID:{
      path: path
    },
    ctorMsg: {
      function:"init",
      args: init_args.map(&:to_s)
    },
    secureContext: user[:id]
  }
end
invoke_payload(chaincode_name, *args) click to toggle source
# File lib/openblockchain-ruby.rb, line 58
def invoke_payload(chaincode_name, *args)
  {
    chaincodeSpec:
      {
        type: "GOLANG",
        chaincodeID:{
          name: chaincode_name
        },
        ctorMsg: {
          function:"invoke",
          args: args.map(&:to_s)
        },
        secureContext: user[:id]
      }
  }
end
post(action, to_send) click to toggle source
# File lib/openblockchain-ruby.rb, line 31
def post(action, to_send)
  request_data = Net::HTTP::Post.new(action, initheader = {'Content-Type' =>'application/json'})
  request_data.body = to_send.to_json
  http.request(request_data)
end
query_payload(chaincode_name, *args) click to toggle source
# File lib/openblockchain-ruby.rb, line 75
def query_payload(chaincode_name, *args)
  {
    chaincodeSpec:
      {
        type: "GOLANG",
        chaincodeID:{
          name: chaincode_name
        },
        ctorMsg: {
          function:"query",
          args:args.map(&:to_s)
        },
        secureContext: user[:id]
      }
  }
end
registrar_payload() click to toggle source
# File lib/openblockchain-ruby.rb, line 37
def registrar_payload
  {
    enrollId: user[:id],
    enrollSecret: user[:secret]
  }
end