appchain.rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3cf165b17b0de81dc3dcc848600339523ad2e7920be7a4f620bdcca802d3525b
4
+ data.tar.gz: 4067ce5f69b9e1b76c7143117ddd6d032348802b478e5afc953f53da722384b1
5
+ SHA512:
6
+ metadata.gz: 839817784fd7e9351b8050e86d7c9353078a971c0d00bc7316f09fb928461ddc3359f05f082d420441f48a8034d559688d3c245424f4fe50cb0059256d6ab9bd
7
+ data.tar.gz: 6fd4a13f92717af89484f62c05f2816e9e19d4521706ddfe4e1ed17540572c375b5358f4d4cce296f1d56ca5a5dc076503ca4038367652dbed49b3b99c494e04
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,6 @@
1
+ [submodule "cita-proto"]
2
+ path = cita-proto
3
+ url = https://github.com/cryptape/cita-proto.git
4
+ [submodule "secp256k1"]
5
+ path = secp256k1
6
+ url = https://github.com/bitcoin-core/secp256k1.git
data/.pryrc ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "awesome_print"
4
+ AwesomePrint.pry!
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,103 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ Exclude:
4
+ - 'spec/**/*'
5
+ - 'bin/*'
6
+ - 'Rakefile'
7
+ - 'Gemfile'
8
+ - 'Gemfile.lock'
9
+ - 'appchain.gemspec'
10
+ - 'cita-proto/**/*'
11
+ - 'secp256k1/**/*'
12
+ - 'lib/appchain/protos/**/*'
13
+
14
+ Bundler/OrderedGems:
15
+ Enabled: false
16
+
17
+ Layout/AccessModifierIndentation:
18
+ EnforcedStyle: indent
19
+
20
+ Layout/EmptyLineAfterMagicComment:
21
+ Enabled: false
22
+
23
+ Layout/SpaceInsideHashLiteralBraces:
24
+ EnforcedStyle: space
25
+
26
+ Metrics/AbcSize:
27
+ Max: 100
28
+
29
+ Metrics/ClassLength:
30
+ CountComments: false
31
+ Max: 300
32
+
33
+ Metrics/CyclomaticComplexity:
34
+ Max: 25
35
+
36
+ Metrics/LineLength:
37
+ AllowURI: true
38
+ Enabled: false
39
+
40
+ Metrics/MethodLength:
41
+ CountComments: false
42
+ Max: 55
43
+
44
+ Metrics/ModuleLength:
45
+ CountComments: false
46
+ Max: 200
47
+
48
+ Metrics/ParameterLists:
49
+ Max: 5
50
+ CountKeywordArgs: true
51
+
52
+ Metrics/PerceivedComplexity:
53
+ Max: 20
54
+
55
+ Naming/MemoizedInstanceVariableName:
56
+ Enabled: false
57
+
58
+ Style/CollectionMethods:
59
+ Enabled: true
60
+ PreferredMethods:
61
+ find_all: 'select'
62
+
63
+ Style/DoubleNegation:
64
+ Enabled: true
65
+
66
+ Style/FrozenStringLiteralComment:
67
+ Enabled: true
68
+
69
+ Style/GuardClause:
70
+ Enabled: false
71
+
72
+ Style/Lambda:
73
+ Enabled: false
74
+
75
+ Style/Documentation:
76
+ Enabled: false
77
+
78
+ Style/PercentLiteralDelimiters:
79
+ PreferredDelimiters:
80
+ '%i': '()'
81
+ '%w': '()'
82
+
83
+ Style/ClassAndModuleChildren:
84
+ Enabled: false
85
+
86
+ Naming/AccessorMethodName:
87
+ Enabled: false
88
+
89
+ Metrics/BlockLength:
90
+ CountComments: false
91
+ Max: 25
92
+ ExcludedMethods:
93
+ - refine
94
+ - included
95
+
96
+ Style/StringLiterals:
97
+ EnforcedStyle: double_quotes
98
+ SupportedStyles:
99
+ - single_quotes
100
+ - double_quotes
101
+ # If `true`, strings which span multiple lines using `\` for continuation must
102
+ # use the same type of quotes on each line.
103
+ ConsistentQuotesInMultiline: false
@@ -0,0 +1,16 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.4
7
+ - 2.5.1
8
+ before_install: gem install bundler -v 1.16.4
9
+ install:
10
+ - cd secp256k1 && ./autogen.sh && ./configure --enable-module-recovery --enable-experimental --enable-module-ecdh && make && sudo make install && cd ..
11
+ - bundle install
12
+ script:
13
+ - bundle exec rake
14
+
15
+ after_success:
16
+ - bash <(curl -s https://codecov.io/bash)
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at classicalliu@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in appchain.gemspec
6
+ gemspec
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ appchain.rb (0.1.0)
5
+ activesupport (~> 5.2.1)
6
+ ciri-crypto (= 0.1.1)
7
+ faraday (~> 0.15.3)
8
+ google-protobuf (~> 3.6)
9
+ web3-eth (~> 0.2.16)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (5.2.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ ast (2.4.0)
20
+ awesome_print (1.8.0)
21
+ bitcoin-secp256k1 (0.4.0)
22
+ ffi (>= 1.9.10)
23
+ ciri-crypto (0.1.1)
24
+ bitcoin-secp256k1 (~> 0.4.0)
25
+ ciri-utils (~> 0.2.0)
26
+ ciri-utils (0.2.2)
27
+ digest-sha3 (~> 1.1.0)
28
+ coderay (1.1.2)
29
+ concurrent-ruby (1.0.5)
30
+ diff-lcs (1.3)
31
+ digest-sha3 (1.1.0)
32
+ faraday (0.15.3)
33
+ multipart-post (>= 1.2, < 3)
34
+ ffi (1.9.25)
35
+ google-protobuf (3.6.1-universal-darwin)
36
+ i18n (1.1.0)
37
+ concurrent-ruby (~> 1.0)
38
+ jaro_winkler (1.5.1)
39
+ method_source (0.9.0)
40
+ minitest (5.11.3)
41
+ multipart-post (2.0.0)
42
+ parallel (1.12.1)
43
+ parser (2.5.1.2)
44
+ ast (~> 2.4.0)
45
+ powerpack (0.1.2)
46
+ pry (0.11.3)
47
+ coderay (~> 1.1.0)
48
+ method_source (~> 0.9.0)
49
+ rainbow (3.0.0)
50
+ rake (10.5.0)
51
+ rlp (0.7.3)
52
+ rspec (3.8.0)
53
+ rspec-core (~> 3.8.0)
54
+ rspec-expectations (~> 3.8.0)
55
+ rspec-mocks (~> 3.8.0)
56
+ rspec-core (3.8.0)
57
+ rspec-support (~> 3.8.0)
58
+ rspec-expectations (3.8.1)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.8.0)
61
+ rspec-mocks (3.8.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.8.0)
64
+ rspec-support (3.8.0)
65
+ rubocop (0.59.2)
66
+ jaro_winkler (~> 1.5.1)
67
+ parallel (~> 1.10)
68
+ parser (>= 2.5, != 2.5.1.1)
69
+ powerpack (~> 0.1)
70
+ rainbow (>= 2.2.2, < 4.0)
71
+ ruby-progressbar (~> 1.7)
72
+ unicode-display_width (~> 1.0, >= 1.0.1)
73
+ ruby-progressbar (1.10.0)
74
+ thread_safe (0.3.6)
75
+ tzinfo (1.2.5)
76
+ thread_safe (~> 0.1)
77
+ unicode-display_width (1.4.0)
78
+ web3-eth (0.2.16)
79
+ digest-sha3 (~> 1.1.0)
80
+ rlp (~> 0.7.3)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ appchain.rb!
87
+ awesome_print (~> 1.8)
88
+ bundler (~> 1.16)
89
+ pry (~> 0.11)
90
+ rake (~> 10.0)
91
+ rspec (~> 3.0)
92
+ rubocop (~> 0.59)
93
+
94
+ BUNDLED WITH
95
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Cryptape
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # AppChain.rb
2
+
3
+ [![Build Status](https://travis-ci.org/cryptape/appchain.rb.svg?branch=master)](https://travis-ci.org/cryptape/appchain.rb)
4
+
5
+ Nervos AppChain Ruby SDK
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'appchain.rb', github: "cryptape/appchain.rb"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install appchain.rb
22
+
23
+ ## Usage
24
+
25
+ See `keccak256`, `to_hex` and other utils methods in `AppChain::Utils` module
26
+
27
+ rpc calls [RPC list](https://docs.nervos.org/cita/#/rpc_guide/rpc)
28
+ ```ruby
29
+ appchain = AppChain::Client.new("your url")
30
+
31
+ appchain.rpc.block_number
32
+ appchain.rpc.get_block_by_number("0x0", true)
33
+ # or
34
+ appchain.rpc.getBlockByNumber("0x0", true)
35
+ ```
36
+
37
+ sign and unsign
38
+ ```ruby
39
+ # make a Transaction object first
40
+ transaction = AppChain::Transaction.new(
41
+ to: "8ff0f5b85fba9a6429e2e256880291774f8e224f",
42
+ nonce: "e4f195c409fe47c58a624de37c730679",
43
+ quota: 30000,
44
+ valid_until_block: 1882078,
45
+ data: "",
46
+ value: "0x3e8",
47
+ chain_id: 1,
48
+ version: 0
49
+ )
50
+
51
+ # sign transaction with your private key
52
+ content = AppChain::TransactionSigner.encode(transaction, "you private key")
53
+
54
+ # you can unsign content by `decode` method
55
+ AppChain::TransactionSigner.decode(content)
56
+ ```
57
+
58
+ send transaction
59
+ ```ruby
60
+ appchain.rpc.send_transaction(transaction, private_key)
61
+ ```
62
+
63
+ transfer tokens
64
+ ```ruby
65
+ appchain.rpc.transfer(to: "to address", value: 1000, private_key)
66
+ ```
67
+
68
+ contract
69
+ ```ruby
70
+ contract = appchain.contract_at(abi, contract_address)
71
+ # for rpc call (constant functions)
72
+ response = contract.call_func(method: :symbol)
73
+ # for rpc sendTransaction
74
+ response = contract.send_func(tx: tx, private_key: private_key, method: :transfer, params: [address, tokens])
75
+ ```
76
+
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cryptape/appchain.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+ ## Code of Conduct
87
+
88
+ Everyone interacting in the appchain.rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cryptape/appchain.rb/blob/master/CODE_OF_CONDUCT.md).