near_api 0.1.3 → 0.1.6

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: a2d52679da22f2e21379007bab1922d1977708033a6181e6b5987d59a0a5579b
4
- data.tar.gz: 82aa0595f95e509277d901430f9140b9978a6369f45a107d9c6feaad4415f3eb
3
+ metadata.gz: 45334f18df28991a38a1e2301b797334ccf9ac72156d0667bfaee2ce16175b86
4
+ data.tar.gz: 3dd56b817520c32493de57a2510ea76e1d2de7563ad5670b38fde97903b060f9
5
5
  SHA512:
6
- metadata.gz: b8489f9a7889bcb819ce8155da38eabd460a7de4173d04f7b979784841d4b0a926f5fb0f4e89e8542a167eed26b5bcfa02f27ab56bcff995710efdab99471b90
7
- data.tar.gz: ce6dfea367c7eef407f99e5d7d624b398469ae3065ca098434599b0177579dae2700a7c33f90b9eb46b662dff4b3179cc00120f2a349fcbb869624ffc5a50459
6
+ metadata.gz: 3f948aa2cb4e9a55993192a273a580a0a987cc13c6c2a2b613bef361e7ac5a604d5ce644ccf9c1312dafcdedca68e521877f31306530a51fb00ea1b0c15aa363
7
+ data.tar.gz: f80f23346467ed75fe3f66bf4a108ae54070f9072f0d786a89e1df6e9402a8995e36f2431107a299fcb0e99f0020160734799bf4c8138c0b4b3aebb517d4439c
@@ -0,0 +1,27 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: rspec
9
+
10
+ on:
11
+ push:
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ concurrency:
16
+ group: ${{ github.ref }}
17
+ cancel-in-progress: true
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: 3.0.2
24
+ - name: Install dependencies
25
+ run: bundle install --path vendor/bundle --jobs 4 --retry 3
26
+ - name: Rspec
27
+ run: bundle exec rspec
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ ![tests](https://github.com/near-rails-guide/near_api/actions/workflows/ci.yml/badge.svg)
1
2
  # NearApi
2
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.
@@ -4,18 +4,22 @@ class NearApi::Base58
4
4
  BASE = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
5
5
 
6
6
  def self.encode(bytestring)
7
- number = bytestring.unpack("C*").reverse.each_with_index.inject(0) do |sum, (byte, index)|
8
- sum + byte * (256 ** index)
7
+ number = bytestring.unpack('C*').reverse.each_with_index.inject(0) do |sum, (byte, index)|
8
+ sum + byte * (256**index)
9
9
  end
10
- tos number
10
+ nzeroes = bytestring.bytes.find_index { |b| b != 0 } || bytestring.length - 1
11
+ prefix = BASE[0] * nzeroes
12
+ prefix + tos(number)
11
13
  end
12
14
 
13
15
  def self.decode(encoded_string)
14
16
  integer = toi encoded_string
15
- to_bytestring(integer)
17
+ nzeroes = encoded_string.chars.find_index { |c| c != BASE[0] } || encoded_string.length - 1
18
+ prefix = nzeroes < 0 ? '' : 0.chr * nzeroes
19
+ prefix + to_bytestring(integer)
16
20
  end
17
21
 
18
- def self.toi(string=to_s, base=58, digits=BASE)
22
+ def self.toi(string = to_s, base = 58, digits = BASE)
19
23
  return nil if string.empty?
20
24
 
21
25
  integer = 0
@@ -26,9 +30,10 @@ class NearApi::Base58
26
30
  integer
27
31
  end
28
32
 
29
- def self.tos(integer=to_i, base=58, digits=BASE)
33
+ def self.tos(integer = to_i, base = 58, digits = BASE)
30
34
  return '' if integer.nil?
31
35
  return digits[0] if integer == 0
36
+
32
37
  string = ''
33
38
  while integer > 0
34
39
  integer, index = integer.divmod(base)
@@ -38,6 +43,8 @@ class NearApi::Base58
38
43
  end
39
44
 
40
45
  def self.to_bytestring(number)
46
+ return 0.chr if number == 0
47
+
41
48
  integer = number
42
49
  result = ''
43
50
  while integer > 0
data/lib/near_api/key.rb CHANGED
@@ -30,7 +30,7 @@ class NearApi::Key
30
30
  public_key
31
31
  end
32
32
  bytestring = NearApi::Base58.decode(key_value)
33
- @public_key = Ed25519::VerifyKey.new(bytestring)
33
+ @public_key = Ed25519::VerifyKey.new(bytestring).to_bytes
34
34
  end
35
35
  end
36
36
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NearApi::Status
4
+ def initialize(config = NearApi.config)
5
+ @api = NearApi::Api.new(config)
6
+ end
7
+
8
+ def transaction_status(transaction_hash, key: NearApi.key)
9
+ params = [transaction_hash, key.signer_id]
10
+ call_api('tx', params)
11
+ end
12
+
13
+ def final_transaction_status(transaction_hash, key: NearApi.key)
14
+ params = [transaction_hash, key.signer_id]
15
+ call_api('EXPERIMENTAL_tx_status', params)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :api
21
+
22
+ def call_api(method, params)
23
+ api.json_rpc(method, params)
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NearApi
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/near_api.rb CHANGED
@@ -3,14 +3,15 @@
3
3
  require 'uri'
4
4
  require 'net/https'
5
5
  require 'json'
6
- require "base64"
6
+ require 'base64'
7
7
  require 'borsh'
8
- require_relative "near_api/version"
9
- require_relative "near_api/key"
10
- require_relative "near_api/action"
8
+ require_relative 'near_api/version'
9
+ require_relative 'near_api/key'
10
+ require_relative 'near_api/status'
11
+ require_relative 'near_api/action'
11
12
  require_relative 'near_api/query'
12
- require_relative "near_api/action/function_call"
13
- require_relative "near_api/config"
13
+ require_relative 'near_api/action/function_call'
14
+ require_relative 'near_api/config'
14
15
  require_relative 'near_api/api'
15
16
  require_relative "near_api/base58"
16
17
 
data/near_api.gemspec CHANGED
@@ -9,13 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["700@2rba.com"]
10
10
 
11
11
  spec.summary = "NEAR blockchain ruby API"
12
- spec.homepage = "https://github.com/2rba/near_api"
12
+ spec.homepage = "https://github.com/near-rails-guide/near_api"
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = ">= 2.4.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/2rba/near_api"
18
- spec.metadata["changelog_uri"] = "https://github.com/2rba/near_api"
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.
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.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serg Tyatin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: borsh-rb
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/ci.yml"
76
77
  - ".gitignore"
77
78
  - ".rspec"
78
79
  - Gemfile
@@ -89,15 +90,16 @@ files:
89
90
  - lib/near_api/config.rb
90
91
  - lib/near_api/key.rb
91
92
  - lib/near_api/query.rb
93
+ - lib/near_api/status.rb
92
94
  - lib/near_api/version.rb
93
95
  - near_api.gemspec
94
- homepage: https://github.com/2rba/near_api
96
+ homepage: https://github.com/near-rails-guide/near_api
95
97
  licenses:
96
98
  - MIT
97
99
  metadata:
98
- homepage_uri: https://github.com/2rba/near_api
99
- source_code_uri: https://github.com/2rba/near_api
100
- changelog_uri: https://github.com/2rba/near_api
100
+ homepage_uri: https://github.com/near-rails-guide/near_api
101
+ source_code_uri: https://github.com/near-rails-guide/near_api
102
+ changelog_uri: https://github.com/near-rails-guide/near_api
101
103
  post_install_message:
102
104
  rdoc_options: []
103
105
  require_paths:
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  - !ruby/object:Gem::Version
114
116
  version: '0'
115
117
  requirements: []
116
- rubygems_version: 3.2.22
118
+ rubygems_version: 3.2.32
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: NEAR blockchain ruby API