cardano_wallet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6e3c345e2c100428cf2bdd638ee903c9df401760a78e75bc531f48d8d2832e3
4
+ data.tar.gz: d11fd3e81378d4ff2d4687d16ebe3cdcfa78cf33d342d2d907ac8b8ab374c70b
5
+ SHA512:
6
+ metadata.gz: a2a32cd78ee9ec09f814b1bb9eca9786327b2da53e82da90067aaa9cca6c7a9d146b9d120115173e0e17e4f154c6d3cdf3c6ba7cbe228ce07f53dc7b435a5d88
7
+ data.tar.gz: 5b2f5263447204632e7d80d8a9e15186a19fa7d33e40ee1a74651c0982aa799157a3b42455ea75aff25cd38db2ba8fea1609506f1ac2689dee3bc31911b950eb
@@ -0,0 +1,29 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby 2.6
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ version: 2.6.x
19
+
20
+ - name: Publish to RubyGems
21
+ run: |
22
+ mkdir -p $HOME/.gem
23
+ touch $HOME/.gem/credentials
24
+ chmod 0600 $HOME/.gem/credentials
25
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
26
+ gem build *.gemspec
27
+ gem push *.gem
28
+ env:
29
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
@@ -0,0 +1,41 @@
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: Tests
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up cardano-wallet
24
+ run: docker-compose up --detach
25
+ - name: Set up Ruby
26
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
27
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
28
+ # uses: ruby/setup-ruby@v1
29
+ uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
30
+ with:
31
+ ruby-version: 2.6
32
+ - name: Install dependencies
33
+ run: bundle install
34
+ - name: Run tests
35
+ run: bundle exec rake
36
+ env:
37
+ CI: true
38
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
39
+ NETWORK: testnet
40
+ WALLET: dev-master-byron
41
+ NODE: latest
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -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 piotr.stachyra@iohk.io. 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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cardano_wallet.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Piotr Stachyra
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.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ <a href="https://github.com/piotr-iohk/cardano-wallet-rb/releases">
2
+ <img src="https://img.shields.io/github/release/piotr-iohk/cardano-wallet-rb.svg" />
3
+ </a>
4
+ <a href="https://codecov.io/gh/piotr-iohk/cardano-wallet-rb">
5
+ <img src="https://codecov.io/gh/piotr-iohk/cardano-wallet-rb/branch/master/graph/badge.svg?token=OmUMUeyR21" />
6
+ </a>
7
+ <a href="https://github.com/piotr-iohk/cardano-wallet-rb/actions?query=workflow%3ATests">
8
+ <img src="https://github.com/piotr-iohk/cardano-wallet-rb/workflows/Tests/badge.svg" />
9
+ </a>
10
+
11
+ # cardano-wallet-rb
12
+
13
+ Ruby wrapper over [cardano-wallet's](https://github.com/input-output-hk/cardano-wallet) REST [API](https://input-output-hk.github.io/cardano-wallet/api/edge/).
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'cardano_wallet'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle install
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install cardano_wallet
30
+
31
+ ## Usage
32
+
33
+ ### Initialize
34
+
35
+ ```ruby
36
+ # default options
37
+ CW = CardanoWallet.new
38
+
39
+ # custom options
40
+ CW1 = CardanoWallet.new({port: 8091})
41
+ CW2 = CardanoWallet.new({port: 443,
42
+ protocol: "https",
43
+ cacert: "/root/ca.cert",
44
+ pem: "/root/client.pem"})
45
+ ```
46
+ ### Excercise the API
47
+ ```ruby
48
+ CW = CardanoWallet.new
49
+
50
+ BYRON = CW.byron
51
+ SHELLEY = CW.shelley
52
+ MISC = CW.misc
53
+ PROXY = CW.proxy
54
+
55
+ #Byron
56
+ BYRON.wallets.list.each_with_index do |wal, i|
57
+ BYRON.wallets.update_metadata(wal['id'], {name: "Wallet number #{i}"})
58
+ end
59
+
60
+ #Shelley
61
+ w = SHELLEY.wallets.create{name: "Wallet1",
62
+ mnemonic_sentence: %w[vintage poem topic machine hazard cement dune glimpse fix brief account badge mass silly business],
63
+ passphrase: "Secure Passphrase"}
64
+
65
+ SHELLEY.wallets.get(w['id'])
66
+
67
+ #Misc
68
+ MISC.network.information
69
+ MISC.network.clock
70
+
71
+ #Proxy
72
+ PROXY.submit_external_transaction(File.new("/tmp/blob.bin").read)
73
+ ```
74
+
75
+ Refer to documentation.
76
+
77
+ ## Development
78
+
79
+ In order to spin up environment for development and testing `docker-compose` can be used.
80
+
81
+ $ NETWORK=testnet WALLET=dev-master-byron NODE=latest docker-compose up --detach
82
+
83
+ This starts:
84
+ - `cardano-node` latest [release](https://github.com/input-output-hk/cardano-node/releases)
85
+ - `cardano-wallet-byron` [master](https://github.com/input-output-hk/cardano-wallet)
86
+
87
+ Run tests on top of that:
88
+
89
+ $ rake
90
+
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/piotr-iohk/cardano-wallet-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/piotr-iohk/cardano-wallet-rb/blob/master/CODE_OF_CONDUCT.md).
95
+
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
100
+
101
+ ## Code of Conduct
102
+
103
+ Everyone interacting in the `cardano-wallet-rb` project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotr-iohk/cardano-wallet-rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cardano_wallet"
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__)
data/bin/setup ADDED
@@ -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,37 @@
1
+ require_relative 'lib/cardano_wallet/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "cardano_wallet"
5
+ spec.version = CardanoWallet::VERSION
6
+ spec.authors = ["Piotr Stachyra"]
7
+ spec.email = ["piotr.stachyra@gmail.com"]
8
+
9
+ spec.summary = %q{Ruby wrapper over cardano-wallet.}
10
+ spec.description = %q{Ruby wrapper over cardano-wallet.}
11
+ spec.homepage = "https://github.com/piotr-iohk/cardano-wallet-rb"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency 'httparty', '~> 0.18.0'
31
+
32
+ spec.add_development_dependency 'rake', '~> 12.3'
33
+ spec.add_development_dependency 'rspec', '~> 3.7'
34
+ spec.add_development_dependency 'codecov'
35
+ spec.add_development_dependency 'simplecov'
36
+
37
+ end
@@ -0,0 +1,38 @@
1
+ version: "3.5"
2
+
3
+ services:
4
+ cardano-node:
5
+ image: inputoutput/cardano-node:${NODE}
6
+ environment:
7
+ NETWORK:
8
+ volumes:
9
+ - node-${NETWORK}-db:/data
10
+ - node-ipc:/ipc
11
+ - node-config:/nix/store
12
+ restart: on-failure
13
+
14
+ cardano-wallet:
15
+ image: inputoutput/cardano-wallet:${WALLET}
16
+ volumes:
17
+ - wallet-${NETWORK}-db:/wallet-db
18
+ - node-ipc:/ipc
19
+ - node-config:/config
20
+ ports:
21
+ - 8090:8090
22
+ entrypoint: []
23
+ command: bash -c "
24
+ ([[ $$NETWORK == \"mainnet\" ]] && $$CMD --mainnet) ||
25
+ ([[ $$NETWORK == \"testnet\" ]] && $$CMD --testnet /config/*testnet-genesis.json)
26
+ "
27
+ environment:
28
+ CMD: "cardano-wallet-byron serve --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0"
29
+ NETWORK:
30
+ restart: on-failure
31
+
32
+ volumes:
33
+ node-mainnet-db:
34
+ node-testnet-db:
35
+ wallet-mainnet-db:
36
+ wallet-testnet-db:
37
+ node-ipc:
38
+ node-config:
@@ -0,0 +1,15 @@
1
+ require "httparty"
2
+
3
+ require_relative "cardano_wallet/version"
4
+ require_relative "cardano_wallet/base"
5
+ require_relative "cardano_wallet/utils"
6
+ require_relative "cardano_wallet/shelley"
7
+ require_relative "cardano_wallet/byron"
8
+ require_relative "cardano_wallet/misc"
9
+ require_relative "cardano_wallet/proxy"
10
+
11
+ module CardanoWallet
12
+ def self.new(options = {})
13
+ CardanoWallet::Base.new(options)
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module CardanoWallet
2
+ class Base
3
+ include HTTParty
4
+
5
+ attr_reader :opt
6
+
7
+ def initialize(opt = {})
8
+ raise ArgumentError, "argument should be Hash" unless opt.is_a?(Hash)
9
+
10
+ opt[:protocol] ||= 'http'
11
+ opt[:host] ||= 'localhost'
12
+ opt[:port] ||= 8090
13
+ opt[:url] ||= "#{opt[:protocol]}://#{opt[:host]}:#{opt[:port]}/v2"
14
+ opt[:cacert] ||= ''
15
+ opt[:pem] ||= ''
16
+ self.class.base_uri opt[:url]
17
+
18
+ unless opt[:cacert].empty?
19
+ ENV['SSL_CERT_FILE'] = opt[:cacert]
20
+ self.class.ssl_ca_file(File.read ENV['SSL_CERT_FILE'])
21
+ end
22
+ self.class.pem(File.read opt[:pem]) unless opt[:pem].empty?
23
+
24
+ @opt = opt
25
+ end
26
+
27
+ # Init API for Shelley
28
+ def shelley
29
+ Shelley.new @opt
30
+ end
31
+
32
+ # Init API for Byron
33
+ def byron
34
+ Byron.new @opt
35
+ end
36
+
37
+ # Init API for Misc
38
+ def misc
39
+ Misc.new @opt
40
+ end
41
+
42
+ # Init API for Proxy
43
+ def proxy
44
+ Proxy.new @opt
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,238 @@
1
+ module CardanoWallet
2
+ module Byron
3
+
4
+ def self.new(opt)
5
+ Init.new opt
6
+ end
7
+
8
+ class Init < Base
9
+ def initialize opt
10
+ super
11
+ end
12
+
13
+ # Get API for Byron wallets
14
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Wallets
15
+ def wallets
16
+ Wallets.new @opt
17
+ end
18
+
19
+ # Get API for Byron addresses
20
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Addresses
21
+ def addresses
22
+ Addresses.new @opt
23
+ end
24
+
25
+ # Get API for Byron transactions
26
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee
27
+ def transactions
28
+ Transactions.new @opt
29
+ end
30
+
31
+ # Get API for Byron migrations
32
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Migrations
33
+ def migrations
34
+ Migrations.new @opt
35
+ end
36
+ end
37
+
38
+ # Byron wallets
39
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Wallets
40
+ class Wallets < Base
41
+ def initialize opt
42
+ super
43
+ end
44
+
45
+ # List Byron wallets
46
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronWallets
47
+ def list
48
+ self.class.get("/byron-wallets")
49
+ end
50
+
51
+ # Get Byron wallet details
52
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronWallet
53
+ def get(wid)
54
+ self.class.get("/byron-wallets/#{wid}")
55
+ end
56
+
57
+ # Create a Byron wallet based on the params.
58
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronWallet
59
+ #
60
+ # @example
61
+ # create({style: "random",
62
+ # name: "Random Wallet from mnemonic_sentence",
63
+ # passphrase: "Secure Passphrase",
64
+ # mnemonic_sentence: %w[arctic decade pink easy jar index base bright vast ocean hard pizza],
65
+ # })
66
+ def create(params)
67
+ Utils.verify_param_is_hash!(params)
68
+ self.class.post( "/byron-wallets",
69
+ :body => params.to_json,
70
+ :headers => { 'Content-Type' => 'application/json' }
71
+ )
72
+ end
73
+
74
+ # Delete Byron wallet
75
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/deleteByronWallet
76
+ def delete(wid)
77
+ self.class.delete("/byron-wallets/#{wid}")
78
+ end
79
+
80
+ # Update Byron wallet's metadata
81
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putByronWallet
82
+ #
83
+ # @example
84
+ # update_metadata(wid, {name: "New wallet name"})
85
+ def update_metadata(wid, params)
86
+ Utils.verify_param_is_hash!(params)
87
+ self.class.put("/byron-wallets/#{wid}",
88
+ :body => params.to_json,
89
+ :headers => { 'Content-Type' => 'application/json' }
90
+ )
91
+ end
92
+
93
+ # See Byron wallet's utxo distribution
94
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronUTxOsStatistics
95
+ def utxo(wid)
96
+ self.class.get("/byron-wallets/#{wid}/statistics/utxos")
97
+ end
98
+
99
+ # Update Byron wallet's passphrase.
100
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putByronWalletPassphrase
101
+ #
102
+ # @example
103
+ # update_passphrase(wid, {old_passphrase: "Secure Passphrase", new_passphrase: "Securer Passphrase"})
104
+ def update_passphrase(wid, params)
105
+ Utils.verify_param_is_hash!(params)
106
+ self.class.put("/byron-wallets/#{wid}/passphrase",
107
+ :body => params.to_json,
108
+ :headers => { 'Content-Type' => 'application/json' }
109
+ )
110
+ end
111
+ end
112
+
113
+ # Byron addresses
114
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Addresses
115
+ class Addresses < Base
116
+ def initialize opt
117
+ super
118
+ end
119
+
120
+ # List Byron addresses.
121
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronAddresses
122
+ #
123
+ # @example
124
+ # list(wid, {state: "used"})
125
+ def list(wid, q = {})
126
+ q.empty? ? query = '' : query = Utils.to_query(q)
127
+ self.class.get("/byron-wallets/#{wid}/addresses#{query}")
128
+ end
129
+
130
+ # Create address for Byron random wallet.
131
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/createAddress
132
+ # @param wid [String] wallet id
133
+ # @param params [Hash] passphrase and (optional) address_index
134
+ #
135
+ # @example Create address with index.
136
+ # create(wid, {passphrase: "Secure Passphrase", address_index: 2147483648})
137
+ # @example Create address with random index.
138
+ # create(wid, {passphrase: "Secure Passphrase"})
139
+ def create(wid, params)
140
+ Utils.verify_param_is_hash!(params)
141
+ self.class.post( "/byron-wallets/#{wid}/addresses",
142
+ :body => params.to_json,
143
+ :headers => { 'Content-Type' => 'application/json' }
144
+ )
145
+ end
146
+
147
+ # Import address to Byron wallet.
148
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/importAddress
149
+ # @param wid [String] wallet id
150
+ # @param addr_id [String] address id
151
+ def import(wid, addr_id)
152
+ self.class.put("/byron-wallets/#{wid}/addresses/#{addr_id}")
153
+ end
154
+
155
+ end
156
+
157
+ # Byron transactions
158
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee
159
+ class Transactions < Base
160
+ def initialize opt
161
+ super
162
+ end
163
+
164
+ # List all Byron wallet's transactions.
165
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronTransactions
166
+ #
167
+ # @example
168
+ # list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
169
+ def list(wid, q = {})
170
+ q.empty? ? query = '' : query = Utils.to_query(q)
171
+ self.class.get("/byron-wallets/#{wid}/transactions#{query}")
172
+ end
173
+
174
+ # Create a transaction from the Byron wallet.
175
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransaction
176
+ # @param wid [String] source wallet id
177
+ # @param passphrase [String] source wallet's passphrase
178
+ # @param payments [Hash] addres, amount pair
179
+ #
180
+ # @example
181
+ # create(wid, passphrase, {addr1: 1000000})
182
+ def create(wid, passphrase, payments)
183
+ payments_formatted = Utils.format_payments(payments)
184
+ self.class.post("/byron-wallets/#{wid}/transactions",
185
+ :body => { :payments => payments_formatted,
186
+ :passphrase => passphrase
187
+ }.to_json,
188
+ :headers => { 'Content-Type' => 'application/json' } )
189
+ end
190
+
191
+ # Estimate fees for transaction
192
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionFee
193
+ #
194
+ # @example
195
+ # payment_fees(wid, {addr1: 1000000})
196
+ def payment_fees(wid, payments)
197
+ payments_formatted = Utils.format_payments(payments)
198
+ self.class.post("/byron-wallets/#{wid}/payment-fees",
199
+ :body => { :payments => payments_formatted }.to_json,
200
+ :headers => { 'Content-Type' => 'application/json' } )
201
+ end
202
+
203
+ # Forget a transaction.
204
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/deleteByronTransaction
205
+ def forget(wid, txid)
206
+ self.class.delete("/byron-wallets/#{wid}/transactions/#{txid}")
207
+ end
208
+ end
209
+
210
+ # Byron migrations
211
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Migrations
212
+ class Migrations < Base
213
+ def initialize opt
214
+ super
215
+ end
216
+
217
+ # Calculate migration cost
218
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronWalletMigrationInfo
219
+ def cost(wid)
220
+ self.class.get("/byron-wallets/#{wid}/migrations")
221
+ end
222
+
223
+ # Migrate all funds from Byron wallet.
224
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/migrateByronWallet
225
+ # @param wid [String] wallet id
226
+ # @param passphrase [String] wallet's passphrase
227
+ # @param [Array] array of addresses
228
+ def migrate(wid, passphrase, addresses)
229
+ self.class.post("/byron-wallets/#{wid}/migrations",
230
+ :body => { :addresses => addresses,
231
+ :passphrase => passphrase
232
+ }.to_json,
233
+ :headers => { 'Content-Type' => 'application/json' } )
234
+ end
235
+
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,47 @@
1
+ module CardanoWallet
2
+ module Misc
3
+
4
+ def self.new(opt)
5
+ Init.new opt
6
+ end
7
+
8
+ class Init < Base
9
+ def initialize opt
10
+ super
11
+ end
12
+
13
+ # Call API for Network
14
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Network
15
+ def network
16
+ Network.new @opt
17
+ end
18
+ end
19
+
20
+ # API for Network
21
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Network
22
+ class Network < Base
23
+ def initialize opt
24
+ super
25
+ end
26
+
27
+ # Get network information
28
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getNetworkInformation
29
+ def information
30
+ self.class.get("/network/information")
31
+ end
32
+
33
+ # Check network clock
34
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getNetworkClock
35
+ def clock
36
+ self.class.get("/network/clock")
37
+ end
38
+
39
+ # Check network parameters
40
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getNetworkParameters
41
+ def parameters(epoch_id)
42
+ self.class.get("/network/parameters/#{epoch_id}")
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,26 @@
1
+ module CardanoWallet
2
+ module Proxy
3
+
4
+ # Call API for Proxy
5
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
6
+ def self.new(opt)
7
+ Init.new opt
8
+ end
9
+
10
+ class Init < Base
11
+ def initialize opt
12
+ super
13
+ end
14
+
15
+ # Submit a transaction that was created and signed outside of cardano-wallet.
16
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postExternalTransaction
17
+ # @param binary_blob [String] Signed transaction message binary blob.
18
+ def submit_external_transaction(binary_blob)
19
+ self.class.post("/proxy/transactions",
20
+ :body => binary_blob,
21
+ :headers => { 'Content-Type' => 'application/octet-stream' })
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,254 @@
1
+ module CardanoWallet
2
+ # Init API for Shelley
3
+ module Shelley
4
+
5
+ def self.new(opt)
6
+ Init.new opt
7
+ end
8
+
9
+ class Init < Base
10
+
11
+ def initialize opt
12
+ super
13
+ end
14
+
15
+ # Call API for Wallets
16
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Wallets
17
+ def wallets
18
+ Wallets.new @opt
19
+ end
20
+
21
+ # API for Addresses
22
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Addresses
23
+ def addresses
24
+ Addresses.new @opt
25
+ end
26
+
27
+ # API for CoinSelections
28
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Coin-Selections
29
+ def coin_selections
30
+ CoinSelections.new @opt
31
+ end
32
+
33
+ # API for Transactions
34
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
35
+ def transactions
36
+ Transactions.new @opt
37
+ end
38
+
39
+ # API for StakePools
40
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
41
+ def stake_pools
42
+ StakePools.new @opt
43
+ end
44
+
45
+ end
46
+
47
+ # API for Wallets
48
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Wallets
49
+ class Wallets < Base
50
+ def initialize opt
51
+ super
52
+ end
53
+
54
+ # List all wallets
55
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listWallets
56
+ def list
57
+ self.class.get("/wallets")
58
+ end
59
+
60
+ # Get wallet details
61
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getWallet
62
+ def get(wid)
63
+ self.class.get("/wallets/#{wid}")
64
+ end
65
+
66
+ # Create a wallet based on the params.
67
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postWallet
68
+ #
69
+ # @example Create wallet from mnemonic sentence
70
+ # create({name: "Wallet from mnemonic_sentence",
71
+ # passphrase: "Secure Passphrase",
72
+ # mnemonic_sentence: %w[story egg fun dismiss gasp mad spoon human cloud become garbage panel rhythm knee help],
73
+ # })
74
+ # @example Create wallet from pub key
75
+ # create({name: "Wallet from pub key",
76
+ # account_public_key: "b47546e661b6c1791452d003d375756dde6cac2250093ce4630f16b9b9c0ac87411337bda4d5bc0216462480b809824ffb48f17e08d95ab9f1b91d391e48e66b",
77
+ # address_pool_gap: 20,
78
+ # })
79
+ def create(params)
80
+ Utils.verify_param_is_hash!(params)
81
+ self.class.post( "/wallets",
82
+ :body => params.to_json,
83
+ :headers => { 'Content-Type' => 'application/json' }
84
+ )
85
+ end
86
+
87
+ # Delete wallet
88
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/deleteWallet
89
+ def delete(wid)
90
+ self.class.delete("/wallets/#{wid}")
91
+ end
92
+
93
+ # Update wallet's metadata
94
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putWallet
95
+ #
96
+ # @example
97
+ # update_metadata(wid, {name: "New wallet name"})
98
+ def update_metadata(wid, params)
99
+ Utils.verify_param_is_hash!(params)
100
+ self.class.put("/wallets/#{wid}",
101
+ :body => params.to_json,
102
+ :headers => { 'Content-Type' => 'application/json' }
103
+ )
104
+ end
105
+
106
+ # See wallet's utxo distribution
107
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getUTxOsStatistics
108
+ def utxo(wid)
109
+ self.class.get("/wallets/#{wid}/statistics/utxos")
110
+ end
111
+
112
+ # Update wallet's passphrase
113
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putWalletPassphrase
114
+ #
115
+ # @example
116
+ # update_passphrase(wid, {old_passphrase: "Secure Passphrase", new_passphrase: "Securer Passphrase"})
117
+ def update_passphrase(wid, params)
118
+ Utils.verify_param_is_hash!(params)
119
+ self.class.put("/wallets/#{wid}/passphrase",
120
+ :body => params.to_json,
121
+ :headers => { 'Content-Type' => 'application/json' }
122
+ )
123
+ end
124
+ end
125
+
126
+ # API for Addresses
127
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Addresses
128
+ class Addresses < Base
129
+ def initialize opt
130
+ super
131
+ end
132
+
133
+ # List addresses
134
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listAddresses
135
+ #
136
+ # @example
137
+ # list(wid, {state: "used"})
138
+ def list(wid, q = {})
139
+ q.empty? ? query = '' : query = Utils.to_query(q)
140
+ self.class.get("/wallets/#{wid}/addresses#{query}")
141
+ end
142
+ end
143
+
144
+ # API for CoinSelections
145
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Coin-Selections
146
+ class CoinSelections < Base
147
+ def initialize opt
148
+ super
149
+ end
150
+
151
+ # Show random coin selection for particular payment
152
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/selectCoins
153
+ #
154
+ # @example
155
+ # random(wid, {address1: 123, address2: 456})
156
+ def random(wid, payments)
157
+ payments_formatted = Utils.format_payments(payments)
158
+ self.class.post("/wallets/#{wid}/coin-selections/random",
159
+ :body => {:payments => payments_formatted}.to_json,
160
+ :headers => { 'Content-Type' => 'application/json' })
161
+ end
162
+ end
163
+
164
+ # API for Transactions
165
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
166
+ class Transactions < Base
167
+ def initialize opt
168
+ super
169
+ end
170
+
171
+ # List all wallet's transactions
172
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listTransactions
173
+ #
174
+ # @example
175
+ # list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
176
+ def list(wid, q = {})
177
+ q.empty? ? query = '' : query = Utils.to_query(q)
178
+ self.class.get("/wallets/#{wid}/transactions#{query}")
179
+ end
180
+
181
+ # Create a transaction from the wallet
182
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction
183
+ # @param wid [String] source wallet id
184
+ # @param passphrase [String] source wallet's passphrase
185
+ # @param payments [Hash] addres, amount pair
186
+ #
187
+ # @example
188
+ # create(wid, passphrase, {addr1: 1000000})
189
+ def create(wid, passphrase, payments)
190
+ payments_formatted = Utils.format_payments(payments)
191
+ self.class.post("/wallets/#{wid}/transactions",
192
+ :body => { :payments => payments_formatted,
193
+ :passphrase => passphrase
194
+ }.to_json,
195
+ :headers => { 'Content-Type' => 'application/json' } )
196
+
197
+ end
198
+
199
+ # Estimate fees for transaction
200
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionFee
201
+ #
202
+ # @example
203
+ # payment_fees(wid, {addr1: 1000000})
204
+ def payment_fees(wid, payments)
205
+ payments_formatted = Utils.format_payments(payments)
206
+ self.class.post("/wallets/#{wid}/payment-fees",
207
+ :body => { :payments => payments_formatted }.to_json,
208
+ :headers => { 'Content-Type' => 'application/json' } )
209
+ end
210
+
211
+ # Forget a transaction
212
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/deleteTransaction
213
+ def forget(wid, txid)
214
+ self.class.delete("/wallets/#{wid}/transactions/#{txid}")
215
+ end
216
+ end
217
+
218
+ # API for StakePools
219
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
220
+ class StakePools < Base
221
+ def initialize opt
222
+ super
223
+ end
224
+
225
+ # List all stake pools
226
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listStakePools
227
+ def list
228
+ self.class.get("/stake-pools")
229
+ end
230
+
231
+ # Join stake pool
232
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/joinStakePool
233
+ def join(sp_id, wid, passphrase)
234
+ self.class.put("/stake-pools/#{sp_id}/wallets/#{wid}",
235
+ :body => { :passphrase => passphrase }.to_json,
236
+ :headers => { 'Content-Type' => 'application/json' } )
237
+ end
238
+
239
+ # Quit stape pool
240
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/quitStakePool
241
+ def quit(wid, passphrase)
242
+ self.class.delete("#{@api}/stake-pools/*/wallets/#{wid}",
243
+ :body => { :passphrase => passphrase }.to_json,
244
+ :headers => { 'Content-Type' => 'application/json' } )
245
+ end
246
+
247
+ # Estimate delegation fees
248
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getDelegationFee
249
+ def delegation_fees(wid)
250
+ self.class.get("/wallets/#{wid}/delegation-fees")
251
+ end
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,27 @@
1
+ module CardanoWallet
2
+ module Utils
3
+
4
+ def self.verify_param_is_hash!(param)
5
+ raise ArgumentError, "argument should be Hash" unless param.is_a?(Hash)
6
+ end
7
+
8
+ def self.format_payments(payments)
9
+ verify_param_is_hash!(payments)
10
+ payments.collect do |addr, amt|
11
+ {:address => addr.to_s,
12
+ :amount => {:quantity => amt.to_i,
13
+ :unit => "lovelace"}
14
+ }
15
+ end
16
+ end
17
+
18
+ def self.to_query(query)
19
+ verify_param_is_hash!(query)
20
+ q = query.collect do |k, v|
21
+ "#{k}=#{v}"
22
+ end.join '&'
23
+ "?#{q}"
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module CardanoWallet
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cardano_wallet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Stachyra
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby wrapper over cardano-wallet.
84
+ email:
85
+ - piotr.stachyra@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".github/workflows/gem-push.yml"
91
+ - ".github/workflows/tests.yml"
92
+ - ".gitignore"
93
+ - ".rakeTasks"
94
+ - ".rspec"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - cardano_wallet.gemspec
103
+ - docker-compose.yml
104
+ - lib/cardano_wallet.rb
105
+ - lib/cardano_wallet/base.rb
106
+ - lib/cardano_wallet/byron.rb
107
+ - lib/cardano_wallet/misc.rb
108
+ - lib/cardano_wallet/proxy.rb
109
+ - lib/cardano_wallet/shelley.rb
110
+ - lib/cardano_wallet/utils.rb
111
+ - lib/cardano_wallet/version.rb
112
+ homepage: https://github.com/piotr-iohk/cardano-wallet-rb
113
+ licenses:
114
+ - MIT
115
+ metadata:
116
+ allowed_push_host: https://rubygems.org/
117
+ homepage_uri: https://github.com/piotr-iohk/cardano-wallet-rb
118
+ source_code_uri: https://github.com/piotr-iohk/cardano-wallet-rb
119
+ changelog_uri: https://github.com/piotr-iohk/cardano-wallet-rb
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.3.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.0.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Ruby wrapper over cardano-wallet.
139
+ test_files: []