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 +4 -4
- data/.github/workflows/ci.yml +27 -0
- data/README.md +1 -0
- data/lib/near_api/base58.rb +13 -6
- data/lib/near_api/key.rb +1 -1
- data/lib/near_api/status.rb +25 -0
- data/lib/near_api/version.rb +1 -1
- data/lib/near_api.rb +7 -6
- data/near_api.gemspec +3 -3
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45334f18df28991a38a1e2301b797334ccf9ac72156d0667bfaee2ce16175b86
|
4
|
+
data.tar.gz: 3dd56b817520c32493de57a2510ea76e1d2de7563ad5670b38fde97903b060f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+

|
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.
|
data/lib/near_api/base58.rb
CHANGED
@@ -4,18 +4,22 @@ class NearApi::Base58
|
|
4
4
|
BASE = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
5
5
|
|
6
6
|
def self.encode(bytestring)
|
7
|
-
number = bytestring.unpack(
|
8
|
-
sum + byte * (256
|
7
|
+
number = bytestring.unpack('C*').reverse.each_with_index.inject(0) do |sum, (byte, index)|
|
8
|
+
sum + byte * (256**index)
|
9
9
|
end
|
10
|
-
|
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
|
-
|
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
@@ -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
|
data/lib/near_api/version.rb
CHANGED
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
|
6
|
+
require 'base64'
|
7
7
|
require 'borsh'
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
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
|
13
|
-
require_relative
|
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/
|
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/
|
18
|
-
spec.metadata["changelog_uri"] = "https://github.com/
|
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.
|
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:
|
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/
|
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/
|
99
|
-
source_code_uri: https://github.com/
|
100
|
-
changelog_uri: https://github.com/
|
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.
|
118
|
+
rubygems_version: 3.2.32
|
117
119
|
signing_key:
|
118
120
|
specification_version: 4
|
119
121
|
summary: NEAR blockchain ruby API
|