garnet_client 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/app/controllers/garnet_notify_controller.rb +94 -0
- data/app/models/garnet_client/notice_deposit.rb +4 -0
- data/app/models/garnet_client/notice_transaction.rb +4 -0
- data/app/models/garnet_client/notice_withdraw.rb +4 -0
- data/config/routes.rb +5 -0
- data/garnet_client.gemspec +1 -0
- data/lib/garnet_client.rb +9 -0
- data/lib/garnet_client/engine.rb +11 -0
- data/lib/garnet_client/railtie.rb +8 -0
- data/lib/garnet_client/version.rb +1 -1
- data/lib/generators/garnet_client/migration_generator.rb +15 -0
- data/lib/generators/garnet_client/templates/migration.rb +49 -0
- data/lib/rake/garnet_client.rake +13 -0
- metadata +25 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c22b33c49595e2ce37cdc78b04460ccdeb12e36c
|
4
|
+
data.tar.gz: 4df857e4de820edccd50d9e6d321a31cb2d20a6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1865476f7a85876ffc0e35454d4a124003d63a1ab63190caac2658ddb04e35f46130bb6d8d26b9504219dcb45d9b150f0cdf0bf1366d2ff790277ce56227dfff
|
7
|
+
data.tar.gz: 1f5dfd06d07482a4e40ef77c7ca752ba93d973d332525ad4f7e613f7b8ffde0565518e6ee5c495ef23787243c4f1ad23e5860f5b5cef579ce248bf55cb0e3233
|
data/README.md
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module GarnetClient
|
4
|
+
class GarnetNotifyController < ::ActionController::Base
|
5
|
+
if _process_action_callbacks.any?{|a| a.filter == :verify_authenticity_token}
|
6
|
+
# ActionController::Base no longer protects from forgery in Rails 5
|
7
|
+
skip_before_filter :verify_authenticity_token
|
8
|
+
end
|
9
|
+
|
10
|
+
layout false
|
11
|
+
|
12
|
+
def deposits
|
13
|
+
rs = request.body.read
|
14
|
+
code = '0'
|
15
|
+
begin
|
16
|
+
msg = JSON.parse(rs)
|
17
|
+
|
18
|
+
notice = GarnetClient::NoticeDeposit.new
|
19
|
+
notice.coin_type = msg['coin_type']
|
20
|
+
notice.contract_address = msg['contract_address']
|
21
|
+
notice.from = msg['from']
|
22
|
+
notice.tx_hash = msg['tx_hash']
|
23
|
+
notice.to = msg['to']
|
24
|
+
notice.value = msg['value']
|
25
|
+
notice.tx_timestamp = msg['timestamp']
|
26
|
+
notice.status = msg['status']
|
27
|
+
notice.notify_id = msg['notify_id']
|
28
|
+
notice.error_msg = msg['error_msg']
|
29
|
+
notice.save!
|
30
|
+
|
31
|
+
rescue JSON::ParserError => e
|
32
|
+
puts e.message
|
33
|
+
puts e.backtrace.inspect
|
34
|
+
code = '1'
|
35
|
+
end
|
36
|
+
|
37
|
+
render text: '{"status": {"code": ' + code + '}}'
|
38
|
+
end
|
39
|
+
|
40
|
+
def withdraws
|
41
|
+
rs = request.body.read
|
42
|
+
code = '0'
|
43
|
+
begin
|
44
|
+
msg = JSON.parse(rs)
|
45
|
+
|
46
|
+
notice = GarnetClient::NoticeWithdraw.new
|
47
|
+
notice.coin_type = msg['coin_type']
|
48
|
+
notice.contract_address = msg['contract_address']
|
49
|
+
notice.from = msg['from']
|
50
|
+
notice.tx_hash = msg['tx_hash']
|
51
|
+
notice.to = msg['to']
|
52
|
+
notice.value = msg['value']
|
53
|
+
notice.tx_timestamp = msg['timestamp']
|
54
|
+
notice.status = msg['status']
|
55
|
+
notice.notify_id = msg['notify_id']
|
56
|
+
notice.error_msg = msg['error_msg']
|
57
|
+
notice.save!
|
58
|
+
|
59
|
+
rescue JSON::ParserError => e
|
60
|
+
puts e.message
|
61
|
+
puts e.backtrace.inspect
|
62
|
+
code = '1'
|
63
|
+
end
|
64
|
+
|
65
|
+
render text: '{"status": {"code": ' + code + '}}'
|
66
|
+
end
|
67
|
+
|
68
|
+
def transactions
|
69
|
+
rs = request.body.read
|
70
|
+
msg = JSON.parse(rs)
|
71
|
+
code = '0'
|
72
|
+
|
73
|
+
begin
|
74
|
+
notice = GarnetClient::NoticeTransaction.new
|
75
|
+
notice.coin_type = msg['coin_type']
|
76
|
+
notice.tx_id = msg['tx_id']
|
77
|
+
notice.tx_hash = msg['tx_hash']
|
78
|
+
notice.tx_timestamp = msg['timestamp']
|
79
|
+
notice.from = msg['from']
|
80
|
+
notice.to = msg['to']
|
81
|
+
notice.value = msg['value']
|
82
|
+
notice.contract_address = msg['contractAddress']
|
83
|
+
notice.status = msg['status']
|
84
|
+
notice.save!
|
85
|
+
rescue JSON::ParserError => e
|
86
|
+
puts e.message
|
87
|
+
puts e.backtrace.inspect
|
88
|
+
code = '1'
|
89
|
+
end
|
90
|
+
|
91
|
+
render text: '{"status": {"code": ' + code + '}}'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/config/routes.rb
ADDED
data/garnet_client.gemspec
CHANGED
data/lib/garnet_client.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require "garnet_client/version"
|
2
|
+
require "garnet_client/engine"
|
2
3
|
require "garnet_client/utils/http_request"
|
3
4
|
require "garnet_client/service"
|
4
5
|
require "garnet_client/result"
|
6
|
+
require "garnet_client/railtie" if defined?(Rails)
|
5
7
|
require 'HTTParty'
|
6
8
|
require 'json'
|
7
9
|
|
@@ -10,6 +12,13 @@ module GarnetClient
|
|
10
12
|
@content_type = 'application/json'
|
11
13
|
@response_headers = {}
|
12
14
|
|
15
|
+
# 接口路径
|
16
|
+
API_POST_NOTICE_DEPOSIT_URL = '/api/garnet_client/notify_deposits'
|
17
|
+
# 接口路径
|
18
|
+
API_POST_NOTICE_WITHDRAW_URL = '/api/garnet_client/notify_withdraws'
|
19
|
+
# 接口路径
|
20
|
+
API_POST_NOTICE_TX_URL = '/api/garnet_client/notify_transactions'
|
21
|
+
|
13
22
|
class<< self
|
14
23
|
# mer_id 商户账号
|
15
24
|
# mer_key 加密key
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class GarnetClient::MigrationGenerator < ::Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
desc 'Installs GarnetClient migration file.'
|
7
|
+
|
8
|
+
def install
|
9
|
+
migration_template 'migration.rb', 'db/migrate/create_garnet_client_notices.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.next_migration_number(dirname)
|
13
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class CreateGarnetClientNotices < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :garnet_client_notice_deposits do |t|
|
4
|
+
t.string :coin_type
|
5
|
+
t.string :contract_address
|
6
|
+
t.string :from
|
7
|
+
t.string :tx_hash
|
8
|
+
t.string :to
|
9
|
+
t.integer :value
|
10
|
+
t.integer :tx_timestamp
|
11
|
+
t.integer :status
|
12
|
+
t.string :notify_id
|
13
|
+
t.string :error_msg
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :garnet_client_notice_withdraws do |t|
|
18
|
+
t.string :coin_type
|
19
|
+
t.string :contract_address
|
20
|
+
t.string :from
|
21
|
+
t.string :tx_hash
|
22
|
+
t.string :to
|
23
|
+
t.integer :value
|
24
|
+
t.integer :tx_timestamp
|
25
|
+
t.integer :status
|
26
|
+
t.string :notify_id
|
27
|
+
t.string :error_msg
|
28
|
+
t.timestamps
|
29
|
+
end
|
30
|
+
|
31
|
+
create_table :garnet_client_notice_transactions do |t|
|
32
|
+
t.string :tx_id
|
33
|
+
t.string :tx_hash
|
34
|
+
t.integer :tx_timestamp
|
35
|
+
t.string :from
|
36
|
+
t.string :to
|
37
|
+
t.integer :value
|
38
|
+
t.string :contract_address
|
39
|
+
t.integer :status
|
40
|
+
t.timestamps
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.down
|
45
|
+
drop_table :garnet_client_notice_deposits
|
46
|
+
drop_table :garnet_client_notice_withdraws
|
47
|
+
drop_table :garnet_client_notice_transactions
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
namespace :garnet_client do
|
4
|
+
namespace :init do
|
5
|
+
desc "Generate garnet_client init file from example"
|
6
|
+
task :create do
|
7
|
+
source = File.join(Gem.loaded_specs["geee_pay"].full_gem_path, "garnet_client.rb")
|
8
|
+
target = File.join(Rails.root, "config", "initializers", "garnet_client.rb")
|
9
|
+
FileUtils.cp_r source, target
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garnet_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tarzansos
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,15 +96,25 @@ files:
|
|
82
96
|
- LICENSE.txt
|
83
97
|
- README.md
|
84
98
|
- Rakefile
|
99
|
+
- app/controllers/garnet_notify_controller.rb
|
100
|
+
- app/models/garnet_client/notice_deposit.rb
|
101
|
+
- app/models/garnet_client/notice_transaction.rb
|
102
|
+
- app/models/garnet_client/notice_withdraw.rb
|
85
103
|
- bin/console
|
86
104
|
- bin/setup
|
105
|
+
- config/routes.rb
|
87
106
|
- garnet_client.gemspec
|
88
107
|
- garnet_client.rb
|
89
108
|
- lib/garnet_client.rb
|
109
|
+
- lib/garnet_client/engine.rb
|
110
|
+
- lib/garnet_client/railtie.rb
|
90
111
|
- lib/garnet_client/result.rb
|
91
112
|
- lib/garnet_client/service.rb
|
92
113
|
- lib/garnet_client/utils/http_request.rb
|
93
114
|
- lib/garnet_client/version.rb
|
115
|
+
- lib/generators/garnet_client/migration_generator.rb
|
116
|
+
- lib/generators/garnet_client/templates/migration.rb
|
117
|
+
- lib/rake/garnet_client.rake
|
94
118
|
homepage: https://github.com/tuminfei/garnet_client
|
95
119
|
licenses:
|
96
120
|
- MIT
|