klaytn 0.0.9 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b56d3d48ae3828ec485ba078021c384df13a57a1d51005b0c11e8924ae92bff
4
- data.tar.gz: 270d7ac818859cb958d19f32e370d57cfc2435913044c7c595974fe65a8b29dc
3
+ metadata.gz: 1c620946e62b78ff80bd0278595c2c361746ae3410aeb29ac9643dcda742a59f
4
+ data.tar.gz: c4783ec33c0f850229432f504732d881b767e4c79e9f3eed4d054bd0bf7ee584
5
5
  SHA512:
6
- metadata.gz: 00a4986d9e149c3bbef87dd2a723f90a4ffb33807014ec12d4fea5161956106f3bc6096001fbaebaff0d8b86d98133261a016f8a95427320827c82732139cdce
7
- data.tar.gz: 3764f35b1f3a2c8e18d8d6f535c26f0c8c7083d70f3a0d0708b1546db0529e314dcc1faa54b62f5108c5c6f9dc9c93a3b1672724ac426a80f5d11e03152d6f7d
6
+ metadata.gz: bfca0a8b675e50ec7fb3a616bcaa2817017601c8a4add61d1b269ef05620aef24149740c05b20d97f251d463a693e7b9e02506929452362d620ab4e4905f8af3
7
+ data.tar.gz: 96cb03c757b0306c232274dddf995450a0e6d0160fee84c6a99d27ec27b95ebf65f03b7bef0d2ca6f0ad544780b69f198b97d18eebce9ba25ed5db2c71f79a43
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- klaytn (0.0.9)
4
+ klaytn (0.1.2)
5
5
  activesupport (>= 4.2)
6
6
  httparty (~> 0.20.0)
7
7
  keccak (~> 1.3)
data/lib/klaytn/base.rb CHANGED
@@ -8,5 +8,6 @@ module Klaytn
8
8
  MISSING_ACCOUNT_POOL_KRN = 'Please provide a KAS Account Pool KRN id to finish linking your KAS Wallet (ex: krn:XXXX:wallet:yyyy...).'.freeze # KAS > Service > Wallet > Account Pool > KRN
9
9
  MISSING_ABI = 'Please provide the contract ABI, an array-like object returned by the compiler.'.freeze
10
10
  FUNCTION_NOT_FOUND = 'Function with definition XXX not found.'.freeze
11
+ MISSING_JSONRPC_METHOD = 'RPC method name required, e.g. klay_blockNumber.'.freeze
11
12
  end
12
13
  end
@@ -29,12 +29,11 @@ module Klaytn
29
29
  JSON.parse(resp.body)
30
30
  end
31
31
 
32
- ## DEPRECATE: definition ex: 'addAddressToWhitelist(address)' - string literal Solidity function definition
33
- # definition ex: 'addAddressToWhitelist' - string literal Solidity function definition, without parameters/parens
32
+ # definition ex: 'addAddressToWhitelist' - string literal Solidity function definition, without params/parens
34
33
  # inputs ex: [OpenStruct.new({ "internalType": "address", "name": "addr", "type": "address" })] - array of dot-notation object from ABI
35
34
  # params ex: ['0x0xxxx'] - array of arguments accepted by function
36
35
 
37
- def invoke_function(definition, params)
36
+ def invoke_function(definition, params, gas: 0)
38
37
  raise MISSING_CONTRACT if contract_address.blank?
39
38
  raise MISSING_ABI if abi.blank?
40
39
 
@@ -44,17 +43,30 @@ module Klaytn
44
43
  built_defintion = "#{definition}(#{found_function[:inputs].map {|i| i[:type]}.join(',')})"
45
44
  built_inputs = found_function[:inputs].map { |i| OpenStruct.new(i) }
46
45
 
47
- body = function_body_builder(built_defintion, built_inputs, params)
46
+ body = function_body_builder(built_defintion, built_inputs, params, gas)
48
47
  resp = HTTParty.post(BASE_URL + '/execute', body: body.to_json, headers: headers.merge('x-krn' => kas_account_pool_krn), basic_auth: basic_auth)
49
48
  JSON.parse(resp.body)
50
49
  end
51
50
 
52
- def function_body_builder(definition, inputs, params)
51
+ def raw_transaction(input_data, gas: 0)
52
+ raise MISSING_CONTRACT if contract_address.blank?
53
+ body = {
54
+ from: kas_account_wallet_address,
55
+ to: contract_address,
56
+ input: input_data,
57
+ gas: gas,
58
+ submit: true
59
+ }
60
+ resp = HTTParty.post(BASE_URL + '/execute', body: body.to_json, headers: headers.merge('x-krn' => kas_account_pool_krn), basic_auth: basic_auth)
61
+ JSON.parse(resp.body)
62
+ end
63
+
64
+ def function_body_builder(definition, inputs, params, gas)
53
65
  {
54
66
  from: kas_account_wallet_address,
55
67
  to: contract_address,
56
68
  input: encoder.encode_function(definition, inputs, params),
57
- # gas: 900000, # better to exclude, otherwise 'insufficient funds' error is common
69
+ gas: gas,
58
70
  submit: true
59
71
  }
60
72
  end
@@ -0,0 +1,22 @@
1
+ module Klaytn
2
+ class JsonRpc < Client
3
+ BASE_URL = 'https://node-api.klaytnapi.com/v1/klaytn'.freeze
4
+
5
+ def invoke_function(opts)
6
+ raise MISSING_JSONRPC_METHOD if opts[:method].blank?
7
+
8
+ body = function_body_builder(opts)
9
+ resp = HTTParty.post(BASE_URL, body: body.to_json, headers: headers.merge('content-type' => 'application/json'), basic_auth: basic_auth)
10
+ JSON.parse(resp.body)
11
+ end
12
+
13
+ def function_body_builder(opts)
14
+ {
15
+ id: opts[:id] || 1,
16
+ jsonrpc: opts[:jsonrpc_version] || "2.0",
17
+ method: opts[:method], # => klay_isContractAccount
18
+ params: opts[:params] # => ["0x4319c81f7894f60c70600cf29ee440ed62e7401e", "earliest"]
19
+ }
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Klaytn
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/klaytn.rb CHANGED
@@ -11,6 +11,7 @@ module Klaytn
11
11
  require 'klaytn/contract'
12
12
  require 'klaytn/decoder'
13
13
  require 'klaytn/encoder'
14
+ require 'klaytn/json_rpc'
14
15
  require 'klaytn/token'
15
16
  require 'klaytn/transaction'
16
17
  require 'klaytn/wallet'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klaytn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Kulp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-03-06 00:00:00.000000000 Z
12
+ date: 2022-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -93,6 +93,7 @@ files:
93
93
  - lib/klaytn/contract.rb
94
94
  - lib/klaytn/decoder.rb
95
95
  - lib/klaytn/encoder.rb
96
+ - lib/klaytn/json_rpc.rb
96
97
  - lib/klaytn/token.rb
97
98
  - lib/klaytn/transaction.rb
98
99
  - lib/klaytn/version.rb