near_api 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45334f18df28991a38a1e2301b797334ccf9ac72156d0667bfaee2ce16175b86
4
- data.tar.gz: 3dd56b817520c32493de57a2510ea76e1d2de7563ad5670b38fde97903b060f9
3
+ metadata.gz: fa4a1b8997930d0b94e6a6a748a47cf5da7f1f80b5538e284b9d332f74429037
4
+ data.tar.gz: c00578f5f62af686602a4b7f87f9ecc713d419a4cc7d7cb8d663597d54245642
5
5
  SHA512:
6
- metadata.gz: 3f948aa2cb4e9a55993192a273a580a0a987cc13c6c2a2b613bef361e7ac5a604d5ce644ccf9c1312dafcdedca68e521877f31306530a51fb00ea1b0c15aa363
7
- data.tar.gz: f80f23346467ed75fe3f66bf4a108ae54070f9072f0d786a89e1df6e9402a8995e36f2431107a299fcb0e99f0020160734799bf4c8138c0b4b3aebb517d4439c
6
+ metadata.gz: 215dced20e4c338fa050e4f6d25e6b7f62511db23056bf9aaaa849d53eadebf7af4151f01b2921ff767cf54c79a9c29525470ebfabd64ed571b552c69eec1f00
7
+ data.tar.gz: ba78a6b6935a1d6e891ea3edb7872fd544a539301c53a61ddbc904f2cc5723f89e210aaebf9d734c022b8e4f66a78120d9e65b8b7809fbeccebda4ce01e18ece
@@ -25,3 +25,7 @@ jobs:
25
25
  run: bundle install --path vendor/bundle --jobs 4 --retry 3
26
26
  - name: Rspec
27
27
  run: bundle exec rspec
28
+ env:
29
+ NEAR_SIGNER_ID: ${{ secrets.NEAR_SIGNER_ID }}
30
+ NEAR_KEYPAIR: ${{ secrets.NEAR_KEYPAIR }}
31
+ NEAR_NODE_URL: ${{ secrets.NEAR_NODE_URL }}
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in near_api.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem 'rake', '~> 13.0'
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  ![tests](https://github.com/near-rails-guide/near_api/actions/workflows/ci.yml/badge.svg)
2
2
  # NearApi
3
3
 
4
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/near_api`. To experiment with that code, run `bin/console` for an interactive prompt.
5
-
6
- TODO: Delete this and the text above, and describe your gem
4
+ [Near Protocol API](https://docs.near.org/docs/api/overview) ruby library
7
5
 
8
6
  ## Installation
9
7
 
@@ -21,19 +19,118 @@ Or install it yourself as:
21
19
 
22
20
  $ gem install near_api
23
21
 
22
+ ## Configuration
23
+
24
+ Via ENV variables:
25
+ - `NEAR_NODE_URL` RPC node url (for ex. `https://rpc.mainnet.near.org`)
26
+ - `NEAR_SIGNER_ID` account name for transactions and `view_access_key` requests (`account_id` in `.near-credentials`)
27
+ - `NEAR_KEYPAIR` base58 encoded private + public keys (`ed25519:4556s...` in `.near-credentials` named as `private_key` )
28
+ if no private key is available public key can be specified as `NEAR_PUBLIC_KEY` for view requests
29
+
30
+ Via explicit params:
31
+ example:
32
+ ```ruby
33
+ key = NearApi::Key.new('account_id.testnet', key_pair: 'ed25519:4556s...')
34
+ config = NearApi::Config.new(node_url: 'https://rpc.testnet.near.org')
35
+ NearApi::Transaction.new(..., key: key, config: config)
36
+ ```
37
+
24
38
  ## Usage
25
39
 
26
- TODO: Write usage instructions here
40
+ Operations:
41
+ - [View](#view)
42
+ - [Transaction](#transaction)
27
43
 
28
- ## Development
44
+ #### `View`
45
+ NearApi::Api instance view methods:
46
+ - [view_access_key](https://docs.near.org/docs/api/rpc/access-keys#view-access-key)
47
+ - [view_access_key_list](https://docs.near.org/docs/api/rpc/access-keys#view-access-key-list)
48
+ - [view_account](https://docs.near.org/docs/api/rpc/contracts#view-account)
29
49
 
30
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+ example:
51
+ ```ruby
52
+ NearApi::Api.new.view_access_key('account_id.testnet')
53
+ ```
54
+ Response: hash as described in NEAR Protocol JS API
31
55
 
32
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+ Other [methods](https://docs.near.org/docs/api/rpc/access-keys#view-access-key-changes-single) can be called as:
57
+ ```ruby
58
+ NearApi::Api.new.json_rpc('EXPERIMENTAL_changes', {
59
+ "changes_type": "single_access_key_changes",
60
+ "keys": [
61
+ {
62
+ "account_id": "example-acct.testnet",
63
+ "public_key": "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM"
64
+ }
65
+ ],
66
+ "finality": "final"
67
+ }
68
+ )
69
+ ```
33
70
 
34
- ## Contributing
71
+ #### Smart contract view function
72
+ [query smart contract](https://docs.near.org/docs/api/rpc/contracts#call-a-contract-function)
73
+
74
+ ```ruby
75
+ NearApi::Query.new.call(
76
+ 'account_id.testnet',
77
+ 'get_num',
78
+ {}
79
+ )
80
+ ```
81
+
82
+ ### `Transaction`
83
+ ```ruby
84
+ NearApi::Transaction.new(
85
+ 'account_id.testnet', # Transaction call receiver
86
+ [NearApi::Actions::FunctionCall.new('increment', {})], # Array of Actions
87
+ key: key, # Optional key
88
+ config: config # Optional config
89
+ ).call
90
+ ```
91
+
92
+ The example above is waiting for [transaction complete](https://docs.near.org/docs/api/rpc/transactions#send-transaction-await)
93
+
94
+ To send transaction [async](https://docs.near.org/docs/api/rpc/transactions#send-transaction-async):
95
+ ```ruby
96
+ NearApi::Transaction.new(...).async
97
+ ```
35
98
 
36
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/near_api.
99
+ Transaction has one or many actions
100
+ Actions:
101
+ - Create Account
102
+ - Deploy Contract
103
+ - Function Call
104
+ - Transfer
105
+ - Stake
106
+ - Add Key
107
+ - Delete Key
108
+ - Delete Account
109
+
110
+ [Specs](https://github.com/near-rails-guide/near_api/tree/master/spec/near_api/actions)
111
+
112
+ #### Transaction status
113
+ [Transaction_status](https://docs.near.org/docs/api/rpc/transactions#transaction-status)
114
+ ```ruby
115
+ NearApi::Status.new.transaction_status(transaction_hash)
116
+ ```
117
+ [Transaction Status with Receipts](https://docs.near.org/docs/api/rpc/transactions#transaction-status-with-receipts)
118
+ ```ruby
119
+ NearApi::Status.new.final_transaction_status(transaction_hash)
120
+ ```
121
+
122
+ #### External Signing
123
+ To sign transaction with external signing service (dedicated secure service or hardware ledger)
124
+ ```ruby
125
+ transaction = NearApi::Transaction.new(...)
126
+ digest = transaction.message.digest
127
+ # sign with external service
128
+ signature = Ed25519::SigningKey.from_keypair(bytestring).sign(digest)
129
+ transaction.call_api('broadcast_tx_commit', transaction.message.message, signature)
130
+ ```
131
+
132
+ ## Contributing
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/near-rails-guide/near_api
37
134
 
38
135
  ## License
39
136
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "near_api"
4
+ require 'bundler/setup'
5
+ require 'near_api'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +11,5 @@ require "near_api"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- require "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NearApi::AccessKey
4
+ include Borsh
5
+
6
+ borsh nonce: :u64,
7
+ permission: :borsh
8
+
9
+ def initialize(permission)
10
+ @permission = permission
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :permission
16
+
17
+ def nonce
18
+ 0
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Actions
5
+ class AddKey
6
+ include Borsh
7
+
8
+ borsh action_code: :u8,
9
+ public_key: { key_type: :u8, public_key: 32 },
10
+ access_key: :borsh
11
+
12
+ def initialize(public_key, permission)
13
+ @public_key = public_key
14
+ @access_key = NearApi::AccessKey.new(permission)
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :public_key, :access_key
20
+
21
+ def action_code
22
+ 5
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Actions
5
+ class CreateAccount
6
+ include Borsh
7
+
8
+ borsh action_code: :u8
9
+
10
+ private
11
+
12
+ def action_code
13
+ 0
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Actions
5
+ class DeleteAccount
6
+ include Borsh
7
+
8
+ borsh action_code: :u8,
9
+ beneficiary_id: :string
10
+
11
+ def initialize(beneficiary_id)
12
+ @beneficiary_id = beneficiary_id
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :beneficiary_id
18
+
19
+ def action_code
20
+ 7
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Actions
5
+ class DeployContract
6
+ include Borsh
7
+
8
+ borsh action_code: :u8,
9
+ contract: :string
10
+
11
+ def initialize(contract)
12
+ @contract = contract
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :contract
18
+
19
+ def action_code
20
+ 1
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Actions
5
+ class FunctionCall
6
+ include Borsh
7
+
8
+ borsh action_code: :u8,
9
+ method_name: :string,
10
+ args: :string,
11
+ gas: :u64,
12
+ amount: :u128
13
+
14
+ def initialize(method_name, args, gas: 100_000_000_000_000, amount: 0)
15
+ @method_name = method_name
16
+ @args = args.is_a?(String) ? args : args.to_json
17
+ @gas = gas
18
+ @amount = amount
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :method_name, :args, :gas, :amount
24
+
25
+ def action_code
26
+ 2
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Actions
5
+ class Transfer
6
+ include Borsh
7
+
8
+ borsh action_code: :u8,
9
+ amount: :u128
10
+
11
+ def initialize(near_amount: nil, amount: nil)
12
+ if (near_amount.nil? && amount.nil?) || (!near_amount.nil? && !amount.nil?)
13
+ raise ArgumentError, 'please specify one of: near_amount or amount'
14
+ end
15
+
16
+ @amount = amount unless amount.nil?
17
+ @amount = Yocto.from_near(near_amount) unless near_amount.nil?
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :amount
23
+
24
+ def action_code
25
+ 3
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/near_api/api.rb CHANGED
@@ -14,14 +14,36 @@ class NearApi::Api
14
14
  JSON.parse(Net::HTTP.get(uri))
15
15
  end
16
16
 
17
- def view_access_key(key)
17
+ def view_access_key(key, finality: 'optimistic')
18
18
  call(
19
19
  'query',
20
20
  {
21
- "request_type": "view_access_key",
21
+ "request_type": 'view_access_key',
22
22
  "account_id": key.signer_id,
23
23
  "public_key": NearApi::Base58.encode(key.public_key),
24
- "finality": 'optimistic'
24
+ "finality": finality
25
+ }
26
+ )
27
+ end
28
+
29
+ def view_access_key_list(account_id, finality: 'optimistic')
30
+ call(
31
+ 'query',
32
+ {
33
+ "request_type": 'view_access_key_list',
34
+ "account_id": account_id,
35
+ "finality": finality
36
+ }
37
+ )
38
+ end
39
+
40
+ def view_account(account_id, finality: 'optimistic')
41
+ call(
42
+ 'query',
43
+ {
44
+ "request_type": 'view_account',
45
+ "account_id": account_id,
46
+ "finality": finality
25
47
  }
26
48
  )
27
49
  end
@@ -37,7 +59,7 @@ class NearApi::Api
37
59
  def json_rpc(method, payload)
38
60
  json_rpc_payload = {
39
61
  id: 'dontcare',
40
- jsonrpc: "2.0",
62
+ jsonrpc: '2.0',
41
63
  method: method,
42
64
  params: payload
43
65
  }
@@ -55,4 +77,3 @@ class NearApi::Api
55
77
 
56
78
  attr_reader :config
57
79
  end
58
-
data/lib/near_api/key.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'ed25519'
3
4
 
4
5
  class NearApi::Key
@@ -9,7 +10,7 @@ class NearApi::Key
9
10
  public_key: ENV.fetch('NEAR_PUBLIC_KEY', nil))
10
11
  @signer_id = signer_id
11
12
  if (!key_pair.nil? && !public_key.nil?) || (key_pair.nil? && public_key.nil?)
12
- raise ArgumentError, "please specify one of: key_pair or public_key"
13
+ raise ArgumentError, 'please specify one of: key_pair or public_key'
13
14
  end
14
15
 
15
16
  unless key_pair.nil?
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Permissions
5
+ class FullAccessPermission
6
+ include Borsh
7
+
8
+ borsh permission_code: :u8
9
+
10
+ private
11
+
12
+ def permission_code
13
+ 1
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ module Permissions
5
+ class FunctionCallPermission
6
+ include Borsh
7
+
8
+ borsh permission_code: :u8,
9
+ allowance: :u128,
10
+ receiver_id: :string,
11
+ method_names: [:string]
12
+
13
+ def initialize(allowance, receiver_id, method_names)
14
+ @allowance = allowance
15
+ @receiver_id = receiver_id
16
+ @method_names = method_names
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :allowance, :receiver_id, :method_names
22
+
23
+ def permission_code
24
+ 0
25
+ end
26
+ end
27
+ end
28
+ end
@@ -5,12 +5,12 @@ class NearApi::Query
5
5
  @api = NearApi::Api.new(config)
6
6
  end
7
7
 
8
- def function(account_id, method_name, args, finality: 'final')
8
+ def call(account_id, method_name, args, finality: 'optimistic')
9
9
  params = {
10
- request_type: 'call_function',
11
- finality: finality,
12
10
  account_id: account_id,
13
11
  method_name: method_name,
12
+ finality: finality,
13
+ request_type: 'call_function',
14
14
  args_base64: Base64.strict_encode64(args.to_json)
15
15
  }
16
16
  call_api(params)
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NearApi
4
+ class Transaction
5
+ include Borsh
6
+
7
+ borsh signer_id: :string,
8
+ key: { key_type: :u8, public_key: 32 },
9
+ nonce: :u64,
10
+ receiver_id: :string,
11
+ block_hash: 32,
12
+ actions: [:borsh]
13
+
14
+ def self.call(*args)
15
+ new(*args).call
16
+ end
17
+
18
+ def self.async(*args)
19
+ new(*args).async
20
+ end
21
+
22
+ def initialize(receiver_id, actions, config: NearApi.config, key: NearApi.key)
23
+ @key = key
24
+ @receiver_id = receiver_id
25
+ @actions = Array(actions)
26
+ @config = config
27
+ @api = NearApi::Api.new(config)
28
+ end
29
+
30
+ def call
31
+ signature = key.sign(message.digest)
32
+ call_api('broadcast_tx_commit', message.message, signature)
33
+ end
34
+
35
+ def async
36
+ signature = key.sign(message.digest)
37
+ call_api('broadcast_tx_async', message.message, signature)
38
+ end
39
+
40
+ def message
41
+ @message ||= begin
42
+ message = to_borsh
43
+ Struct.new(:message, :digest).new(message, Digest::SHA256.digest(message))
44
+ end
45
+ end
46
+
47
+ def transaction_hash
48
+ NearApi::Base58.encode(message.digest)
49
+ end
50
+
51
+ def call_api(method, message, signature)
52
+ signed_transaction = message + Borsh::Integer.new(key.key_type, :u8).to_borsh + signature
53
+ api.json_rpc(method, [Base64.strict_encode64(signed_transaction)])
54
+ end
55
+
56
+ private
57
+
58
+ def signer_id
59
+ key.signer_id
60
+ end
61
+
62
+ def nonce
63
+ api.nonce(key) + 1
64
+ end
65
+
66
+ def block_hash
67
+ api.block_hash
68
+ end
69
+
70
+ attr_reader :receiver_id, :actions, :key, :config, :api
71
+ end
72
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NearApi
4
- VERSION = "0.1.6"
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NearApi::Yocto
4
+ def self.from_near(amount)
5
+ amount * 10**24
6
+ end
7
+
8
+ def self.to_near(amount)
9
+ amount.to_f / 10**24
10
+ end
11
+ end
data/lib/near_api.rb CHANGED
@@ -8,12 +8,21 @@ require 'borsh'
8
8
  require_relative 'near_api/version'
9
9
  require_relative 'near_api/key'
10
10
  require_relative 'near_api/status'
11
- require_relative 'near_api/action'
11
+ require_relative 'near_api/transaction'
12
+ require_relative 'near_api/access_key'
13
+ require_relative 'near_api/api'
12
14
  require_relative 'near_api/query'
13
- require_relative 'near_api/action/function_call'
15
+ require_relative 'near_api/actions/add_key'
16
+ require_relative 'near_api/actions/create_account'
17
+ require_relative 'near_api/actions/function_call'
18
+ require_relative 'near_api/actions/transfer'
19
+ require_relative 'near_api/actions/delete_account'
20
+ require_relative 'near_api/actions/deploy_contract'
14
21
  require_relative 'near_api/config'
15
- require_relative 'near_api/api'
16
- require_relative "near_api/base58"
22
+ require_relative 'near_api/permissions/full_access_permission'
23
+ require_relative 'near_api/permissions/function_call_permission'
24
+ require_relative 'near_api/base58'
25
+ require_relative 'near_api/yocto'
17
26
 
18
27
  module NearApi
19
28
  class Error < StandardError; end
data/near_api.gemspec CHANGED
@@ -1,36 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/near_api/version"
3
+ require_relative 'lib/near_api/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "near_api"
6
+ spec.name = 'near_api'
7
7
  spec.version = NearApi::VERSION
8
- spec.authors = ["Serg Tyatin"]
9
- spec.email = ["700@2rba.com"]
8
+ spec.authors = ['Serg Tyatin']
9
+ spec.email = ['700@2rba.com']
10
10
 
11
- spec.summary = "NEAR blockchain ruby API"
12
- spec.homepage = "https://github.com/near-rails-guide/near_api"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.4.0"
11
+ spec.summary = 'NEAR blockchain ruby API'
12
+ spec.homepage = 'https://github.com/near-rails-guide/near_api'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 2.4.0'
15
15
 
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/near-rails-guide/near_api"
18
- spec.metadata["changelog_uri"] = "https://github.com/near-rails-guide/near_api"
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/near-rails-guide/near_api'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/near-rails-guide/near_api'
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
22
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
24
  end
25
- spec.bindir = "exe"
25
+ spec.bindir = 'exe'
26
26
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
27
+ spec.require_paths = ['lib']
28
28
 
29
- spec.add_dependency "borsh-rb"
30
- spec.add_dependency "ed25519"
29
+ spec.add_dependency 'borsh-rb'
30
+ spec.add_dependency 'ed25519'
31
31
 
32
- spec.add_development_dependency "rspec", "~> 3.10"
33
- spec.add_development_dependency "pry"
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'rspec', '~> 3.10'
34
34
 
35
35
  # Uncomment to register a new dependency of your gem
36
36
  # spec.add_dependency "example-gem", "~> 1.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: near_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serg Tyatin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-31 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: borsh-rb
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.10'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.10'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3.10'
69
69
  description:
70
70
  email:
71
71
  - 700@2rba.com
@@ -83,15 +83,24 @@ files:
83
83
  - bin/console
84
84
  - bin/setup
85
85
  - lib/near_api.rb
86
- - lib/near_api/action.rb
87
- - lib/near_api/action/function_call.rb
86
+ - lib/near_api/access_key.rb
87
+ - lib/near_api/actions/add_key.rb
88
+ - lib/near_api/actions/create_account.rb
89
+ - lib/near_api/actions/delete_account.rb
90
+ - lib/near_api/actions/deploy_contract.rb
91
+ - lib/near_api/actions/function_call.rb
92
+ - lib/near_api/actions/transfer.rb
88
93
  - lib/near_api/api.rb
89
94
  - lib/near_api/base58.rb
90
95
  - lib/near_api/config.rb
91
96
  - lib/near_api/key.rb
97
+ - lib/near_api/permissions/full_access_permission.rb
98
+ - lib/near_api/permissions/function_call_permission.rb
92
99
  - lib/near_api/query.rb
93
100
  - lib/near_api/status.rb
101
+ - lib/near_api/transaction.rb
94
102
  - lib/near_api/version.rb
103
+ - lib/near_api/yocto.rb
95
104
  - near_api.gemspec
96
105
  homepage: https://github.com/near-rails-guide/near_api
97
106
  licenses:
@@ -115,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
124
  - !ruby/object:Gem::Version
116
125
  version: '0'
117
126
  requirements: []
118
- rubygems_version: 3.2.32
127
+ rubygems_version: 3.2.22
119
128
  signing_key:
120
129
  specification_version: 4
121
130
  summary: NEAR blockchain ruby API
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class NearApi::Action::FunctionCall
4
- include Borsh
5
-
6
- borsh action_code: :u8,
7
- method_name: :string,
8
- args: :string,
9
- gas: :u64,
10
- amount: :u128
11
-
12
- def initialize(method_name, args, gas: 100000000000000, amount: 0)
13
- @method_name = method_name
14
- @args = args
15
- @gas = gas
16
- @amount = amount
17
- end
18
-
19
- private
20
-
21
- attr_reader :method_name, :args, :gas, :amount
22
-
23
- def action_code
24
- 2
25
- end
26
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class NearApi::Action
4
- include Borsh
5
-
6
- borsh signer_id: :string,
7
- key: { key_type: :u8, public_key: 32 },
8
- nonce: :u64,
9
- receiver_id: :string,
10
- block_hash: 32,
11
- actions: [:borsh]
12
-
13
- def self.call(*args)
14
- new(*args).call
15
- end
16
-
17
- def self.async(*args)
18
- new(*args).async
19
- end
20
-
21
- def initialize(receiver_id, actions, config: NearApi.config, key: NearApi.key)
22
- @key = key
23
- @receiver_id = receiver_id
24
- @actions = Array(actions)
25
- @config = config
26
- @api = NearApi::Api.new(config)
27
- end
28
-
29
- def call
30
- signature = key.sign(message.digest)
31
- call_api('broadcast_tx_commit', message.message, signature)
32
- end
33
-
34
- def async
35
- signature = key.sign(message.digest)
36
- call_api('broadcast_tx_async', message.message, signature)
37
- end
38
-
39
- def message
40
- @message ||= begin
41
- message = to_borsh
42
- Struct.new(:message, :digest).new(message, Digest::SHA256.digest(message))
43
- end
44
- end
45
-
46
- def call_api(method, message, signature)
47
- signed_transaction = message + Borsh::Integer.new(key.key_type, :u8).to_borsh + signature
48
- api.json_rpc(method, [Base64.strict_encode64(signed_transaction)])
49
- end
50
-
51
- private
52
-
53
- def signer_id
54
- key.signer_id
55
- end
56
-
57
- def nonce
58
- api.nonce(key) + 1
59
- end
60
-
61
- def block_hash
62
- api.block_hash
63
- end
64
-
65
- attr_reader :receiver_id, :actions, :key, :config, :api
66
- end