c-lightningrb 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/lightning/logger.rb +42 -0
- data/lib/lightning/plugin.rb +218 -0
- data/lib/lightning/request.rb +48 -0
- data/lib/lightning/rpc.rb +16 -0
- data/lib/lightning/version.rb +3 -0
- data/lib/lightning.rb +11 -0
- data/rubylightning.gemspec +30 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 217391984ad129f43d5a9c94faf0768d26bf1b58ea3693bb4c63699c74e08c1c
|
4
|
+
data.tar.gz: 3d535c1c49a4952e7f202ba4d6e67c2a90c873e2c2b0c5aa2bd8d1ab8c731a38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bfcbdefe33df305f684fefd8f6c636a9ba709742b409b3aa57a2eabb9f9f1493b70ffabba6fc60e3983eedca3cb44e2ec112a35bf5991e7cc4663648745db6f
|
7
|
+
data.tar.gz: 92440120dc13251e3beba89a0c10dd9c96593d26481f23626711c6de0d9059a8584e0d7db1934468ee3ac160c97f4f779a2e0c1ab8e5f63253330df5d55527b3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rubylightning
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 azuchi@chaintope.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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 azuchi
|
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,80 @@
|
|
1
|
+
# c-lightningrb: A ruby client library for lightningd [](https://travis-ci.org/chaintope/c-lightningrb) [](https://badge.fury.io/rb/c-lightningrb) [](LICENSE)
|
2
|
+
|
3
|
+
This library is for writing c-lightning plugins in Ruby.
|
4
|
+
You can write your own RPC, event notifications, and Hooks in DSL.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'c-lightningrb', require: 'lightning'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install c-lightningrb
|
21
|
+
|
22
|
+
## Examples
|
23
|
+
|
24
|
+
### Writing a plugin
|
25
|
+
|
26
|
+
You can write your own Plugin by inheriting `Lightning::Plugin`.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
#!/usr/bin/env ruby
|
30
|
+
require 'lightning'
|
31
|
+
|
32
|
+
class HelloPlugin < Lightning::Plugin
|
33
|
+
|
34
|
+
# define new rpc. Usage and description are required only for the definition of RPC.
|
35
|
+
desc '[name]', 'Returns a personalized greeting for {greeting} (set via options).'
|
36
|
+
define_rpc :hello, -> (name) do
|
37
|
+
log.info "log = #{log}"
|
38
|
+
"hello #{name}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# add subscription for event notification
|
42
|
+
subscribe :connect, ->(id, address) do
|
43
|
+
log.info "received connect notification. id = #{id}, address = #{address}"
|
44
|
+
end
|
45
|
+
|
46
|
+
subscribe :disconnect, ->(id) do
|
47
|
+
log.info "received disconnect notification. id = #{id}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# add Hook
|
51
|
+
hook :peer_connected, ->(peer) do
|
52
|
+
log.info "peer_connected. peer = #{peer}"
|
53
|
+
{result: 'continue'}
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
p = HelloPlugin.new
|
59
|
+
p.run
|
60
|
+
```
|
61
|
+
|
62
|
+
Write all RPC, notification, and hook handlers in Lambda.
|
63
|
+
These Lambdas are implemented as methods, so you can access any of the fields and methods of the Plugin.
|
64
|
+
|
65
|
+
And it works if you specify Plugin as the parameter when c-lightning launches.
|
66
|
+
|
67
|
+
```
|
68
|
+
$ lightningd --plugin=<above file path>
|
69
|
+
```
|
70
|
+
|
71
|
+
Note: Plugin file needs execute permission.
|
72
|
+
|
73
|
+
Note: If you write logs to stdout with puts etc., it will be sent as a response to lightningd.
|
74
|
+
Therefore, if you want to output the log, please use Plugin#log logger.
|
75
|
+
This log is output to under /tmp/ruby-lightnig directory.
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
80
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lightning"
|
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,42 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
module Lightning
|
5
|
+
|
6
|
+
module Logger
|
7
|
+
|
8
|
+
Format = "%s, [%s#%d #%d] %5s -- %s: %s\n".freeze
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
# Create a logger with given +name+.log in $HOME/tmp/ruby-lightning.
|
13
|
+
def create(name, level = ::Logger::INFO)
|
14
|
+
dir = "#{Dir.tmpdir}/ruby-lightning"
|
15
|
+
FileUtils.mkdir_p(dir)
|
16
|
+
logger = ::Logger.new(dir + "/#{name}.log", 10)
|
17
|
+
logger.level = level
|
18
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
19
|
+
Format % [severity[0..0], format_datetime(datetime), $$,
|
20
|
+
Thread.current.object_id, severity, progname, msg2str(msg)]
|
21
|
+
end
|
22
|
+
logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def msg2str(msg)
|
26
|
+
case msg
|
27
|
+
when ::String
|
28
|
+
msg
|
29
|
+
when ::Exception
|
30
|
+
"#{ msg.message } (#{ msg.class })\n" << (msg.backtrace || []).join("\n")
|
31
|
+
else
|
32
|
+
msg.inspect
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def format_datetime(time)
|
37
|
+
time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Lightning
|
5
|
+
|
6
|
+
class Method
|
7
|
+
|
8
|
+
TYPE = {rpc: 0, hook: 1}
|
9
|
+
|
10
|
+
attr_reader :name
|
11
|
+
attr_reader :type
|
12
|
+
attr_reader :usage
|
13
|
+
attr_reader :desc
|
14
|
+
attr_reader :long_desc
|
15
|
+
|
16
|
+
def initialize(name, usage = nil, desc = nil, type: TYPE[:rpc], long_desc: nil)
|
17
|
+
@name = name
|
18
|
+
@type = type
|
19
|
+
@usage = usage
|
20
|
+
@desc = desc
|
21
|
+
@long_desc = long_desc
|
22
|
+
end
|
23
|
+
|
24
|
+
def rpc?
|
25
|
+
type == TYPE[:rpc] && ![:init, :getmanifest].include?(name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def hook?
|
29
|
+
type == TYPE[:hook]
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_h
|
33
|
+
result = {name: name.to_s, usage: usage, description: desc}
|
34
|
+
result[:long_description] = long_desc if long_desc
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Plugin
|
41
|
+
|
42
|
+
class << self
|
43
|
+
|
44
|
+
# get RPM methods.
|
45
|
+
# @return [Hash] the hash of RPC method.
|
46
|
+
def methods
|
47
|
+
@methods ||= {}
|
48
|
+
end
|
49
|
+
|
50
|
+
# get subscriptions
|
51
|
+
# @return [Hash] the hash of subscriptions
|
52
|
+
def subscriptions
|
53
|
+
@subscriptions ||= []
|
54
|
+
end
|
55
|
+
|
56
|
+
# Define the definition of RPC method
|
57
|
+
# @param [String] usage the usage of RPC method.
|
58
|
+
# @param [String] desc the description of RPC method.
|
59
|
+
# @param [String] long_desc (Optional) the long description of RPC method.
|
60
|
+
def desc(usage, desc, long_desc = nil)
|
61
|
+
@usage = usage
|
62
|
+
@desc = desc
|
63
|
+
@long_desc = long_desc
|
64
|
+
end
|
65
|
+
|
66
|
+
# Define RPC method.
|
67
|
+
# @param [String] name the name of rpc method.
|
68
|
+
# @param [Proc] lambda Lambda which is the substance of RPC method.
|
69
|
+
def define_rpc(name, lambda)
|
70
|
+
m = name.to_sym
|
71
|
+
raise ArgumentError, 'method must be implemented using lambda.' unless lambda.is_a?(Proc) && lambda.lambda?
|
72
|
+
raise ArgumentError, "#{m} was already defined." if methods[m]
|
73
|
+
raise ArgumentError, "usage for #{m} dose not defined." unless @usage
|
74
|
+
raise ArgumentError, "description for #{m} dose not defined." unless @desc
|
75
|
+
define_method(m, lambda)
|
76
|
+
methods[m] = Method.new(m, @usage, @desc, long_desc: @long_desc)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Define Event notification handler.
|
80
|
+
# @param [Symbol] event the event name.
|
81
|
+
# @param [Proc] lambda Lambda which is the event handler.
|
82
|
+
def subscribe(event, lambda)
|
83
|
+
e = event.to_sym
|
84
|
+
raise ArgumentError, 'handler must be implemented using lambda.' unless lambda.is_a?(Proc) && lambda.lambda?
|
85
|
+
raise ArgumentError, "Topic #{e} already has a handler." if subscriptions.include?(e)
|
86
|
+
define_method(e, lambda)
|
87
|
+
subscriptions << e
|
88
|
+
end
|
89
|
+
|
90
|
+
# Define hook handler.
|
91
|
+
# @param [Symbol] event the event name.
|
92
|
+
# @param [Proc] lambda Lambda which is the event handler.
|
93
|
+
def hook(event, lambda)
|
94
|
+
e = event.to_sym
|
95
|
+
raise ArgumentError, 'handler must be implemented using lambda.' unless lambda.is_a?(Proc) && lambda.lambda?
|
96
|
+
raise ArgumentError, "Hook #{e} was already registered." if methods[e]
|
97
|
+
define_method(e, lambda)
|
98
|
+
methods[e] = Method.new(e, type: Method::TYPE[:hook])
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
attr_reader :options
|
104
|
+
attr_reader :stdout
|
105
|
+
attr_reader :stdin
|
106
|
+
attr_reader :log
|
107
|
+
attr_accessor :lightning_dir
|
108
|
+
attr_accessor :rpc_filename
|
109
|
+
attr_accessor :rpc
|
110
|
+
|
111
|
+
def initialize
|
112
|
+
methods[:init] = Method.new(:init)
|
113
|
+
@options = {}
|
114
|
+
@stdout = STDOUT
|
115
|
+
@stdin = STDIN
|
116
|
+
methods[:getmanifest] = Method.new(:getmanifest)
|
117
|
+
@log = Lightning::Logger.create(:plugin)
|
118
|
+
end
|
119
|
+
|
120
|
+
def init(options, configuration)
|
121
|
+
log.info("init")
|
122
|
+
@lightning_dir = configuration['lightning-dir']
|
123
|
+
@rpc_filename = configuration['rpc-file']
|
124
|
+
socket_path = (Pathname.new(lightning_dir) + rpc_filename).to_path
|
125
|
+
@rpc = Lightning::RPC.new(socket_path, log)
|
126
|
+
@options.merge!(options)
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
130
|
+
# get manifest information.
|
131
|
+
# @return [Hash] the manifest.
|
132
|
+
def getmanifest
|
133
|
+
log.info("getmanifest")
|
134
|
+
{
|
135
|
+
options: options.values,
|
136
|
+
rpcmethods: rpc_methods.map(&:to_h),
|
137
|
+
subscriptions: subscriptions,
|
138
|
+
hooks: hook_methods.map(&:name),
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
# shutdown this plugin.
|
143
|
+
def shutdown
|
144
|
+
log.info "Plugin shutdown"
|
145
|
+
end
|
146
|
+
|
147
|
+
# run plugin.
|
148
|
+
def run
|
149
|
+
log.info("Plugin run.")
|
150
|
+
begin
|
151
|
+
partial = ''
|
152
|
+
stdin.each_line do |l|
|
153
|
+
partial << l
|
154
|
+
msgs = partial.split("\n\n", -1)
|
155
|
+
next if msgs.size < 2
|
156
|
+
partial = multi_dispatch(msgs)
|
157
|
+
end
|
158
|
+
rescue Exception => e
|
159
|
+
if e.is_a?(Interrupt)
|
160
|
+
shutdown
|
161
|
+
else
|
162
|
+
log.error e
|
163
|
+
throw e
|
164
|
+
end
|
165
|
+
end
|
166
|
+
log.info("Plugin end.")
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
# get method list
|
172
|
+
# @return [Hash] the hash of method.
|
173
|
+
def methods
|
174
|
+
self.class.methods # delegate to class instance
|
175
|
+
end
|
176
|
+
|
177
|
+
# get subscriptions
|
178
|
+
def subscriptions
|
179
|
+
self.class.subscriptions # delegate to class instance
|
180
|
+
end
|
181
|
+
|
182
|
+
def multi_dispatch(msgs)
|
183
|
+
msgs[0...-1].each do |payload|
|
184
|
+
json = JSON.parse(payload)
|
185
|
+
log.info("receive payload = #{json}")
|
186
|
+
request = Lightning::Request.parse_from_json(self, json)
|
187
|
+
if request.id
|
188
|
+
dispatch_request(request)
|
189
|
+
else
|
190
|
+
dispatch_notification(request)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
msgs[-1]
|
194
|
+
end
|
195
|
+
|
196
|
+
def dispatch_request(request)
|
197
|
+
method = methods[request.method]
|
198
|
+
raise ArgumentError, "No method #{request.method} found." unless method
|
199
|
+
result = request.method_args.empty? ? send(method.name) : send(method.name, *request.method_args)
|
200
|
+
request.apply_result(result) if result
|
201
|
+
end
|
202
|
+
|
203
|
+
def dispatch_notification(request)
|
204
|
+
name = request.method
|
205
|
+
raise ArgumentError, "No handler #{request.method} found." unless subscriptions.include?(request.method)
|
206
|
+
request.method_args.empty? ? send(name) : send(name, *request.method_args)
|
207
|
+
end
|
208
|
+
|
209
|
+
def rpc_methods
|
210
|
+
methods.values.select(&:rpc?)
|
211
|
+
end
|
212
|
+
|
213
|
+
def hook_methods
|
214
|
+
methods.values.select(&:hook?)
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Lightning
|
2
|
+
|
3
|
+
# c-lightning request
|
4
|
+
class Request
|
5
|
+
|
6
|
+
attr_reader :plugin
|
7
|
+
attr_reader :id
|
8
|
+
attr_reader :method
|
9
|
+
attr_reader :params
|
10
|
+
attr_accessor :result
|
11
|
+
attr_reader :log
|
12
|
+
|
13
|
+
def initialize(plugin, id, method, params)
|
14
|
+
@plugin = plugin
|
15
|
+
@id = id
|
16
|
+
@method = method
|
17
|
+
@params = params
|
18
|
+
@log = plugin.log
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_from_json(plugin, json)
|
22
|
+
self.new(plugin, json['id'], json['method']&.to_sym, json['params'])
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_args
|
26
|
+
if params.is_a?(Array)
|
27
|
+
params
|
28
|
+
elsif params.is_a?(Hash)
|
29
|
+
params.values
|
30
|
+
else
|
31
|
+
raise ArgumentError, "params does not support format. #{params}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def apply_result(result)
|
36
|
+
@result = result
|
37
|
+
json = {
|
38
|
+
jsonrpc: '2.0',
|
39
|
+
id: id,
|
40
|
+
result: result
|
41
|
+
}.to_json
|
42
|
+
log.info "write response: #{json.to_s}"
|
43
|
+
plugin.stdout.write(json.to_s + "\n\n")
|
44
|
+
plugin.stdout.flush
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/lightning.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "lightning/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "c-lightningrb"
|
8
|
+
spec.version = Lightning::VERSION
|
9
|
+
spec.authors = ["azuchi"]
|
10
|
+
spec.email = ["azuchi@chaintope.com"]
|
11
|
+
|
12
|
+
spec.summary = 'A ruby client library for lightningd'
|
13
|
+
spec.description = 'A ruby client library for lightningd'
|
14
|
+
spec.homepage = "https://github.com/chaintope/c-lightningrb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: c-lightningrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- azuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A ruby client library for lightningd
|
56
|
+
email:
|
57
|
+
- azuchi@chaintope.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/lightning.rb
|
75
|
+
- lib/lightning/logger.rb
|
76
|
+
- lib/lightning/plugin.rb
|
77
|
+
- lib/lightning/request.rb
|
78
|
+
- lib/lightning/rpc.rb
|
79
|
+
- lib/lightning/version.rb
|
80
|
+
- rubylightning.gemspec
|
81
|
+
homepage: https://github.com/chaintope/c-lightningrb
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.0.3
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: A ruby client library for lightningd
|
104
|
+
test_files: []
|