bytom 1.0.1

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.
File without changes
@@ -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 xiudongy@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,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bytom.gemspec
4
+ gemspec
5
+ gem "http"
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bytom (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ domain_name (0.5.20180417)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http (4.0.1)
14
+ addressable (~> 2.3)
15
+ http-cookie (~> 1.0)
16
+ http-form_data (~> 2.0)
17
+ http_parser.rb (~> 0.6.0)
18
+ http-cookie (1.0.3)
19
+ domain_name (~> 0.5)
20
+ http-form_data (2.1.1)
21
+ http_parser.rb (0.6.0)
22
+ minitest (5.8.3)
23
+ public_suffix (3.0.3)
24
+ rake (10.4.2)
25
+ unf (0.1.4)
26
+ unf_ext
27
+ unf_ext (0.0.7.5)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 2.0)
34
+ bytom!
35
+ http
36
+ minitest (~> 5.0)
37
+ rake (~> 10.0)
38
+
39
+ BUNDLED WITH
40
+ 2.0.1
@@ -0,0 +1,145 @@
1
+ # Bytom SDK for Ruby
2
+
3
+ This page will document the API classes and ways to properly use the API. Subsequent new releases also maintain backward compatibility with this class approach. For more information, please see Bytom API reference documentation at [Bytom wiki](https://github.com/Bytom/bytom/wiki/API-Reference)
4
+
5
+ ## System Requirements
6
+
7
+ The SDK supports Ruby versions 2.3.0 or later.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'bytom', '>= 1.0.1'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install bytom
24
+
25
+ ## Example Usage
26
+
27
+ ### Initialize the client
28
+
29
+ ```ruby
30
+ require "bytom"
31
+
32
+ # for local node
33
+ bytom_client = Bytom::Client.new(base_url: 'http://127.0.0.1:9888')
34
+ # for remoate node
35
+ bytom_client = Bytom::Client.new(base_url: 'xxx', token: 'xxx')
36
+ ```
37
+
38
+ ### Create a key
39
+
40
+ ```ruby
41
+ key_data = bytom_client.keys.create_key(
42
+ alias_name: 'bitdayone001',
43
+ password: '123456',
44
+ language: 'en'
45
+ )
46
+ ```
47
+
48
+ ### Create an account
49
+
50
+ ```ruby
51
+ account_data = bytom_client.accounts.create_account(
52
+ root_xpubs: [key_data['data']['xpub']],
53
+ alias_name: 'bitdayone001_account_01',
54
+ quorum: 1
55
+ )
56
+ ```
57
+
58
+ ### Create an account receiver
59
+
60
+ ```ruby
61
+ account_receiver_data = bytom_client.accounts.create_account_receiver(
62
+ account_id: account_data['data']['id'],
63
+ account_alias: account_data['data']['alias']
64
+ )
65
+ ```
66
+
67
+ ### Create an asset
68
+
69
+ ```ruby
70
+ asset_data = bytom_client.asset.create_asset(
71
+ alias_name: 'PropertyAsset',
72
+ root_xpubs: [key_data['data']['xpub']],
73
+ quorum: 1
74
+ )
75
+ ```
76
+
77
+ ### Issue asset
78
+
79
+ #### Firstly build the transaction
80
+
81
+ ```ruby
82
+ actions = [
83
+ {
84
+ account_id: account_data['data']['id'],
85
+ amount: 20000000, # fee, unit: neu. 1 BTM = 1000 mBTM = 100000000 neu
86
+ asset_id: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
87
+ type: "spend_account"
88
+ },
89
+ {
90
+ amount: 100000,
91
+ asset_id: asset_data['data']['id'],
92
+ type: "issue"
93
+ }, # input action
94
+ {
95
+ amount: 100000,
96
+ asset_id: asset_data['data']['id'],
97
+ address: account_receiver_data['data']['address'],
98
+ type: "control_address"
99
+ } # output action
100
+ ]
101
+ build_transaction_data = bytom_client.transactions.build_transaction(
102
+ base_transaction: nil,
103
+ ttl: 0,
104
+ time_range: 129829,
105
+ actions: actions
106
+ )
107
+ ```
108
+
109
+ #### Secondly sign the transaction
110
+
111
+ ```ruby
112
+ transaction = {
113
+ allow_additional_actions: false,
114
+ local: true,
115
+ raw_transaction: build_transaction_data['data']['raw_transaction'],
116
+ signing_instructions: build_transaction_data['data']['signing_instructions']
117
+ }
118
+ sign_transaction_data = bytom_client.transactions.sign_transaction(
119
+ password: '123456',
120
+ transaction: transaction
121
+ )
122
+ ```
123
+
124
+ #### Finally submit the transaction
125
+
126
+ ```ruby
127
+ bytom_client.transactions.submit_transaction(
128
+ raw_transaction: sign_transaction_data['data']['transaction']['raw_transaction']
129
+ )
130
+
131
+ # reponse data if success
132
+ {"status"=>"success", "data"=>{"tx_id"=>"77045241ea94ceee617f12b698a4bdef84cd6e16a58f3191b08fe092f247834d"}}
133
+ ```
134
+
135
+ ## All API usage examples
136
+
137
+ All api usage examples you can see [doc](https://github.com/bitdayone/bytom-ruby-sdk/blob/master/API-Reference.md).
138
+
139
+ ## Support and Feedback
140
+
141
+ If you find a bug, please submit the issue in Github directly by using [Issues](https://github.com/bitdayone/bytom-ruby-sdk/issues)
142
+
143
+ ## License
144
+
145
+ Bytom Ruby SDK is based on the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) protocol.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bytom"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bytom/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bytom"
8
+ spec.version = Bytom::VERSION
9
+ spec.authors = ["BitDayOne"]
10
+ spec.email = ["bitdayone@gmail.com"]
11
+
12
+ spec.summary = "Bytom SDK for ruby"
13
+ spec.description = "Bytom SDK for ruby"
14
+ spec.homepage = "https://bytom.io/"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/bitdayone/bytom-ruby-sdk"
23
+ spec.metadata["changelog_uri"] = "https://github.com/bitdayone/bytom-ruby-sdk/master/CHANGELOG.md"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency 'http'
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "minitest", "~> 5.0"
42
+ end
@@ -0,0 +1,2 @@
1
+ require "bytom/version"
2
+ require 'bytom/client'
@@ -0,0 +1,55 @@
1
+ module Bytom
2
+ class AccessToken
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Create access token, it provides basic access authentication for HTTP protocol, returns token contain username and password, they are separated by a colon.
12
+ #
13
+ #
14
+ # @param [String] id token ID.
15
+ # @param [String] type optional type of token.
16
+ #
17
+ def create_access_token(id:, type: nil)
18
+ params = {
19
+ id: id,
20
+ type: type
21
+ }
22
+ client.make_request('/create-access-token', 'post', params: params)
23
+ end
24
+
25
+ ##
26
+ # Returns the list of all available access tokens.
27
+ #
28
+ def list_access_tokens
29
+ client.make_request('/list-access-tokens', 'post', params: {})
30
+ end
31
+
32
+ ##
33
+ # Delete existed access token.
34
+ #
35
+ # @param [String] id
36
+ #
37
+ def delete_access_token(id:)
38
+ client.make_request('/delete-access-token', 'post', params: {id: id})
39
+ end
40
+
41
+ ##
42
+ # Check access token is valid.
43
+ #
44
+ # @param [String] id
45
+ # @param [String] secret
46
+ #
47
+ def check_access_token(id: , secret:)
48
+ params = {
49
+ id: id,
50
+ secret: secret
51
+ }
52
+ client.make_request('/check-access-token', 'post', params: params)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,111 @@
1
+ module Bytom
2
+ class Accounts
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Create account to manage addresses. single sign account contain only one root_xpubs and quorum; however multi sign account contain many number of root_xpubs and quorum, quorum is the number of verify signature, the range is [1, len(root_xpubs)].
12
+ #
13
+ # @param [Array] root_xpubs
14
+ # @param [Object] alias_name
15
+ # @param [Object] quorum
16
+ # @param [Object] access_token optional
17
+ #
18
+ # @return [Hash]
19
+ #
20
+ def create_account(root_xpubs:[], alias_name:, quorum: 1, access_token: nil)
21
+ params = {
22
+ root_xpubs: root_xpubs,
23
+ alias: alias_name,
24
+ quorum: quorum,
25
+ access_token: access_token
26
+ }
27
+ client.make_request('/create-account', 'post', params: params)
28
+ end
29
+
30
+ ##
31
+ # Returns the list of all available accounts.
32
+ #
33
+ # @return [Hash]
34
+ #
35
+ def list_accounts(id: nil, alias_name:nil)
36
+ params = {}
37
+ params = {id: id} if id
38
+ params = {alias: alias_name} if alias_name
39
+ client.make_request('/list-accounts', 'post', params: params)
40
+ end
41
+
42
+ ##
43
+ # By account id to update alias for the existed account.
44
+ #
45
+ # @param [String] account_id
46
+ # @param [String] new_alias
47
+ #
48
+ # @return [nil] nil if the account alias is updated successfully.
49
+ #
50
+ def update_account_alias_by_id(account_id:, new_alias:)
51
+ params = {
52
+ account_id: account_id,
53
+ new_alias: new_alias
54
+ }
55
+ client.make_request('/update-account-alias', 'post', params: params)
56
+ end
57
+
58
+ ##
59
+ # By account alias to update alias for the existed account.
60
+ #
61
+ # @param [String] account_alias
62
+ # @param [String] new_alias
63
+ #
64
+ # @return [Nil] nil if the account alias is updated successfully.
65
+ #
66
+ def update_account_alias_by_alias(account_alias:, new_alias:)
67
+ params = {
68
+ account_alias: account_alias,
69
+ new_alias: new_alias
70
+ }
71
+ client.make_request('/update-account-alias', 'post', params: params)
72
+ end
73
+
74
+ ##
75
+ # Delete existed account by account id, please make sure that there is no balance in the related addresses.
76
+ #
77
+ # @param [String] account_id
78
+ #
79
+ # @return [Nil] nil if the account alias is updated successfully.
80
+ #
81
+ def delete_account_by_id(account_id:)
82
+ client.make_request('/delete-account', 'post', params: {account_id: account_id})
83
+ end
84
+
85
+ ##
86
+ # Delete existed account by account alias, please make sure that there is no balance in the related addresses.
87
+ # @param [String] account_alias
88
+ #
89
+ # @return [Nil] nil if the account alias is updated successfully.
90
+ #
91
+ def delete_account_by_alias(account_alias:)
92
+ client.make_request('/delete-account', 'post', params: {account_alias: account_alias})
93
+ end
94
+
95
+ ##
96
+ # create address and control program, the address and control program is are one to one relationship. in build-transaction API, receiver is address when action type is control_address, and receiver is control program when action type is control_program, they are the same result.
97
+ #
98
+ # @param [String] account_id
99
+ # @param [String] account_alias
100
+ #
101
+ # @return [Hash]
102
+ #
103
+ def create_account_receiver(account_id: nil, account_alias: nil )
104
+ params = {}
105
+ params = { account_id: account_id } if account_id
106
+ params = { account_alias: account_alias } if account_alias
107
+ return {status: 'failed'} if not params
108
+ client.make_request('/create-account-receiver', 'post', params: params)
109
+ end
110
+ end
111
+ end