trident_assistant 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78044f2cab71b01faa20d88f6e46cc1231e6716d6f1a2e1c7f1ab4566c12a8c8
4
- data.tar.gz: ffe521c1a183c2924ab38358bebe0e3e657f825b5b6e2be16a5c1962cc0beb8c
3
+ metadata.gz: de7cf235f053d71b3bc4eb821255f42bf92311d387a4642ed6b22cce1955b55a
4
+ data.tar.gz: d7cf3912ba6a2f01d9db67fa41da73be4d9301fa93b77ccc569f2d49632a5c24
5
5
  SHA512:
6
- metadata.gz: 6a56b4a274b0e74f19d2dbeb4e04738ccd653dfaa33588482eb62f7a921537ee9dbb24ae36a042d691fb11f2e77c103a078b8002ba3d435362875894ed818d12
7
- data.tar.gz: a60869ceb2bceb39c86b4dc57a9ef35fca14da6246472efe8856cf8acbb8af08a9c18a544e83c921c0f27d47608a2dbb4cf34174146521f16c98f8deb7105305
6
+ metadata.gz: a1ff15e0276ab20e2edaf987e62951f00b04b63113b63223da2a6561f1f229cb077995e2b7016b01d03a99d85df3939385a2ff4e803c98bb9433cd51175d25f0
7
+ data.tar.gz: 19f4d1812f6894cf06c371ee5a97b6f3be5b1413789ad19a679fd7ec1b8364b7e267765b1a3f78a714f4f1308c38f24103cca4281c6d14ba40d4acb0fcd818dc
@@ -11,14 +11,14 @@ module TridentAssistant
11
11
  client
12
12
  .get(
13
13
  "api/collectibles",
14
- headers: {
15
- Authorization: "Bearer #{mixin_bot.access_token("GET", "/me")}"
16
- },
17
- params: {
14
+ {
18
15
  collection_id: kwargs[:collection_id],
19
16
  type: kwargs[:type],
20
17
  page: kwargs[:page],
21
18
  query: kwargs[:query]
19
+ },
20
+ {
21
+ Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
22
22
  }
23
23
  )
24
24
  end
@@ -121,7 +121,7 @@ module TridentAssistant
121
121
  tx = mixin_bot.sign_raw_transaction raw
122
122
 
123
123
  request = mixin_bot.create_sign_collectible_request tx
124
- sign = mixin_bot.sign_collectible_request request["request_id"], keystore[:pin]
124
+ sign = mixin_bot.sign_collectible_request request["request_id"], keystore[:spend_key] || keystore[:pin]
125
125
  mixin_bot.send_raw_transaction sign["raw_transaction"]
126
126
  end
127
127
  end
@@ -13,11 +13,11 @@ module TridentAssistant
13
13
  def collections(**kwargs)
14
14
  client.get(
15
15
  "api/collections",
16
- headers: {
17
- Authorization: "Bearer #{mixin_bot.access_token("GET", "/me")}"
18
- },
19
- params: {
16
+ {
20
17
  page: kwargs[:page]
18
+ },
19
+ {
20
+ Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
21
21
  }
22
22
  )
23
23
  end
@@ -27,16 +27,17 @@ module TridentAssistant
27
27
  client
28
28
  .post(
29
29
  "api/collections",
30
- headers: {
31
- Authorization: "Bearer #{mixin_bot.access_token("GET", "/me")}"
32
- },
33
- json: {
30
+ {
34
31
  name: kwargs[:name],
32
+ symbol: kwargs[:symbol],
35
33
  description: kwargs[:description],
36
34
  external_url: kwargs[:external_url],
37
- split: kwargs[:split].to_f.round(2),
35
+ split: kwargs[:split].to_f.round(4),
38
36
  icon_base64: kwargs[:icon_base64],
39
37
  icon_url: kwargs[:icon_url]
38
+ },
39
+ {
40
+ Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
40
41
  }
41
42
  )
42
43
  end
@@ -46,15 +47,15 @@ module TridentAssistant
46
47
  client
47
48
  .put(
48
49
  "api/collections/#{id}",
49
- headers: {
50
- Authorization: "Bearer #{mixin_bot.access_token("GET", "/me")}"
51
- },
52
- json: {
50
+ {
53
51
  description: kwargs[:description],
54
52
  external_url: kwargs[:external_url],
55
53
  icon_base64: kwargs[:icon_base64],
56
54
  icon_url: kwargs[:icon_url]
57
- }.compact
55
+ }.compact,
56
+ {
57
+ Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
58
+ }
58
59
  )
59
60
  end
60
61
  end
@@ -12,12 +12,12 @@ module TridentAssistant
12
12
  client
13
13
  .post(
14
14
  "api/collectibles",
15
- headers: {
16
- Authorization: "Bearer #{mixin_bot.access_token("GET", "/me")}"
17
- },
18
- json: {
15
+ {
19
16
  metadata: metadata,
20
17
  metahash: metahash
18
+ },
19
+ {
20
+ Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
21
21
  }
22
22
  )
23
23
  end
@@ -8,19 +8,19 @@ module TridentAssistant
8
8
  MINIMUM_AMOUNT = 0.000_000_01
9
9
 
10
10
  def orders(**kwargs)
11
- authorization = mixin_bot ? mixin_bot.access_token("GET", "/me") : ""
11
+ authorization = mixin_bot ? mixin_bot.access_token("GET", "/me", "") : ""
12
12
  client.get(
13
13
  "api/orders",
14
- headers: {
15
- Authorization: "Bearer #{authorization}"
16
- },
17
- params: {
14
+ {
18
15
  collection_id: kwargs[:collection_id],
19
16
  metahash: kwargs[:metahash],
20
17
  state: kwargs[:state],
21
18
  type: kwargs[:type],
22
19
  maker_id: kwargs[:maker_id],
23
20
  page: kwargs[:page]
21
+ },
22
+ {
23
+ Authorization: "Bearer #{authorization}"
24
24
  }
25
25
  )
26
26
  end
@@ -29,8 +29,9 @@ module TridentAssistant
29
29
  client
30
30
  .get(
31
31
  "api/orders/#{id}",
32
- headers: {
33
- Authorization: "Bearer #{mixin_bot.access_token("GET", "/me")}"
32
+ nil,
33
+ {
34
+ Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
34
35
  }
35
36
  )
36
37
  end
@@ -54,14 +55,12 @@ module TridentAssistant
54
55
 
55
56
  mixin_bot.create_multisig_transaction(
56
57
  keystore[:pin],
57
- {
58
- asset_id: EXCHANGE_ASSET_ID,
59
- trace_id: trace_id,
60
- amount: MINIMUM_AMOUNT,
61
- memo: memo.encode,
62
- receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
63
- threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
64
- }
58
+ asset_id: EXCHANGE_ASSET_ID,
59
+ trace_id: trace_id,
60
+ amount: MINIMUM_AMOUNT,
61
+ memo: memo.encode,
62
+ receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
63
+ threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
65
64
  )
66
65
  end
67
66
 
@@ -85,14 +84,12 @@ module TridentAssistant
85
84
 
86
85
  mixin_bot.create_multisig_transaction(
87
86
  keystore[:pin],
88
- {
89
- asset_id: EXCHANGE_ASSET_ID,
90
- trace_id: trace_id,
91
- amount: MINIMUM_AMOUNT,
92
- memo: memo.encode,
93
- receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
94
- threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
95
- }
87
+ asset_id: EXCHANGE_ASSET_ID,
88
+ trace_id: trace_id,
89
+ amount: MINIMUM_AMOUNT,
90
+ memo: memo.encode,
91
+ receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
92
+ threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
96
93
  )
97
94
  end
98
95
 
@@ -114,40 +111,36 @@ module TridentAssistant
114
111
 
115
112
  mixin_bot.create_multisig_transaction(
116
113
  keystore[:pin],
117
- {
118
- asset_id: kwargs[:asset_id],
119
- trace_id: trace_id,
120
- amount: kwargs[:price],
121
- memo: memo.encode,
122
- receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
123
- threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
124
- }
114
+ asset_id: kwargs[:asset_id],
115
+ trace_id: trace_id,
116
+ amount: kwargs[:price],
117
+ memo: memo.encode,
118
+ receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
119
+ threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
125
120
  )
126
121
  end
127
122
 
128
123
  def fill_order(order_id)
129
124
  info = order order_id
130
- raise "Order state: #{info["state"]}" if info["state"] != "open"
125
+ raise ForbiddenError, "Order state: #{info["state"]}" if info["state"] != "open"
131
126
 
132
127
  memo = TridentAssistant::Utils::Memo.new(type: "F", order_id: order_id, token_id: info["token_id"])
133
128
 
134
129
  trace_id = SecureRandom.uuid
135
130
  mixin_bot.create_multisig_transaction(
136
131
  keystore[:pin],
137
- {
138
- asset_id: info["type"] == "BidOrder" ? EXCHANGE_ASSET_ID : info["asset_id"],
139
- trace_id: trace_id,
140
- amount: info["type"] == "BidOrder" ? MINIMUM_AMOUNT : info["price"],
141
- memo: memo.encode,
142
- receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
143
- threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
144
- }
132
+ asset_id: info["type"] == "BidOrder" ? EXCHANGE_ASSET_ID : info["asset_id"],
133
+ trace_id: trace_id,
134
+ amount: info["type"] == "BidOrder" ? MINIMUM_AMOUNT : info["price"],
135
+ memo: memo.encode,
136
+ receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
137
+ threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
145
138
  )
146
139
  end
147
140
 
148
141
  def cancel_order(order_id)
149
142
  info = order order_id
150
- raise ForbiddenError, "Order maker: #{info["maker"]["id"]}" if info.dig("maker", "id") != mixin_bot.client_id
143
+ raise ForbiddenError, "Order maker: #{info["maker"]["id"]}" if info.dig("maker", "id") != mixin_bot.app_id
151
144
  raise ForbiddenError, "Order state: #{info["state"]}" if info["state"] != "open"
152
145
 
153
146
  memo = TridentAssistant::Utils::Memo.new(type: "C", order_id: order_id, token_id: info["token_id"])
@@ -155,14 +148,12 @@ module TridentAssistant
155
148
  trace_id = SecureRandom.uuid
156
149
  mixin_bot.create_multisig_transaction(
157
150
  keystore[:pin],
158
- {
159
- asset_id: EXCHANGE_ASSET_ID,
160
- trace_id: trace_id,
161
- amount: MINIMUM_AMOUNT,
162
- memo: memo.encode,
163
- receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
164
- threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
165
- }
151
+ asset_id: EXCHANGE_ASSET_ID,
152
+ trace_id: trace_id,
153
+ amount: MINIMUM_AMOUNT,
154
+ memo: memo.encode,
155
+ receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
156
+ threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
166
157
  )
167
158
  end
168
159
  end
@@ -17,7 +17,7 @@ module TridentAssistant
17
17
  attr_reader :mixin_bot, :client, :keystore
18
18
 
19
19
  def initialize(**args)
20
- @client = Client.new endpoint: args[:endpoint]
20
+ @client = Client.new endpoint: args[:endpoint], debug: args[:debug]
21
21
  return if args[:keystore].blank?
22
22
 
23
23
  @keystore = TridentAssistant::Utils.parse_json args[:keystore]
@@ -11,7 +11,7 @@ module TridentAssistant
11
11
  desc "new", "generate a new metadata"
12
12
  option :keystore, type: :string, aliases: "k", required: true, desc: "keystore or keystore.json file of Mixin bot"
13
13
  def new
14
- creator_id = api.mixin_bot.client_id
14
+ creator_id = api.mixin_bot.config.app_id
15
15
  creator_name = api.mixin_bot.me["full_name"]
16
16
  creator_royalty = UI.ask("Please input creator royalty, 0.0 ~ 0.1", default: "0.0")
17
17
  raise InvalidError, "Royalty must in 0.0 ~ 0.1" unless (0..0.1).include?(creator_royalty.to_f)
@@ -20,7 +20,7 @@ module TridentAssistant
20
20
  collection = api.collection collection_id
21
21
  raise InvalidError, "Cannot find collection #{collection_id}" if collection.blank?
22
22
 
23
- if collection["creator"]&.[]("id") != api.mixin_bot.client_id
23
+ if collection["creator"]&.[]("id") != api.mixin_bot.config.app_id
24
24
  raise InvalidError,
25
25
  "Unauthorized to mint in #{collection_id}"
26
26
  end
@@ -59,7 +59,7 @@ module TridentAssistant
59
59
  metadata.validate!
60
60
  log UI.fmt("{{v}} metadata validated")
61
61
 
62
- raise "Creator ID incompatible with keystore" if metadata.creator[:id] != api.mixin_bot.client_id
62
+ raise "Creator ID incompatible with keystore" if metadata.creator[:id] != api.mixin_bot.config.app_id
63
63
 
64
64
  # upload metadata
65
65
  if data.dig("_mint", "metahash").blank?
@@ -91,14 +91,12 @@ module TridentAssistant
91
91
  payment =
92
92
  api.mixin_bot.create_multisig_transaction(
93
93
  api.keystore[:pin],
94
- {
95
- asset_id: TridentAssistant::Utils::MINT_ASSET_ID,
96
- trace_id: trace_id,
97
- amount: TridentAssistant::Utils::MINT_AMOUNT,
98
- memo: memo,
99
- receivers: TridentAssistant::Utils::NFO_MTG[:members],
100
- threshold: TridentAssistant::Utils::NFO_MTG[:threshold]
101
- }
94
+ asset_id: TridentAssistant::Utils::MINT_ASSET_ID,
95
+ trace_id: trace_id,
96
+ amount: TridentAssistant::Utils::MINT_AMOUNT,
97
+ memo: memo,
98
+ receivers: TridentAssistant::Utils::NFO_MTG[:members],
99
+ threshold: TridentAssistant::Utils::NFO_MTG[:threshold]
102
100
  )
103
101
 
104
102
  log UI.fmt("{{v}} NFT mint payment paid: #{payment["data"]}")
@@ -12,105 +12,25 @@ module TridentAssistant
12
12
 
13
13
  def initialize(**kwargs)
14
14
  @endpoint = URI(kwargs[:endpoint] || ENDPOINT)
15
- end
16
-
17
- def get(path, **options)
18
- request(:get, path, **options)
19
- end
20
-
21
- def post(path, **options)
22
- request(:post, path, **options)
23
- end
24
-
25
- def put(path, **options)
26
- request(:put, path, **options)
27
- end
28
-
29
- private
30
-
31
- def request(verb, path, **options)
32
- uri = uri_for path
33
-
34
- options[:headers] ||= {}
35
- options[:headers]["Content-Type"] ||= "application/json"
36
-
37
- begin
38
- response = HTTP.timeout(connect: 5, write: 120, read: 60).request(verb, uri, options)
39
- rescue HTTP::Error => e
40
- raise HttpError, e.message
41
- end
42
-
43
- raise RequestError, response.to_s unless response.status.success?
44
-
45
- parse_response(response) do |parse_as, result|
46
- case parse_as
47
- when :json
48
- break result if result.is_a?(Array) || (result.is_a?(Hash) && result["message"].blank?)
49
-
50
- raise result["message"]
51
- else
52
- result
53
- end
15
+ @conn = Faraday.new(url: @endpoint.to_s) do |f|
16
+ f.request :json
17
+ f.request :retry
18
+ f.response :raise_error
19
+ f.response :json
20
+ f.response :logger if kwargs[:debug]
54
21
  end
55
22
  end
56
23
 
57
- def uri_for(path)
58
- uri_options = {
59
- scheme: endpoint.scheme,
60
- host: endpoint.host,
61
- port: endpoint.port,
62
- path: path
63
- }
64
- Addressable::URI.new(uri_options)
24
+ def get(path, params = nil, headers = nil)
25
+ @conn.get(path, params&.compact, headers).body
65
26
  end
66
27
 
67
- def parse_response(response)
68
- content_type = response.headers[:content_type]
69
- parse_as = {
70
- %r{^application/json} => :json,
71
- %r{^image/.*} => :file,
72
- %r{^text/html} => :xml,
73
- %r{^text/plain} => :plain
74
- }.each_with_object([]) { |match, memo| memo << match[1] if content_type =~ match[0] }.first || :plain
75
-
76
- if parse_as == :plain
77
- result = JSON.parse(response&.body&.to_s)
78
- result && yield(:json, result)
79
-
80
- yield(:plain, response.body)
81
- end
82
-
83
- case parse_as
84
- when :json
85
- result = JSON.parse(response.body.to_s)
86
- when :file
87
- extension =
88
- if response.headers[:content_type] =~ %r{^image/.*}
89
- {
90
- "image/gif": ".gif",
91
- "image/jpeg": ".jpg",
92
- "image/png": ".png"
93
- }[response.headers["content-type"]]
94
- else
95
- ""
96
- end
97
-
98
- begin
99
- file = Tempfile.new(["mixin-file-", extension])
100
- file.binmode
101
- file.write(response.body)
102
- ensure
103
- file&.close
104
- end
105
-
106
- result = file
107
- when :xml
108
- result = Hash.from_xml(response.body.to_s)
109
- else
110
- result = response.body
111
- end
28
+ def post(path, body = nil, headers = nil)
29
+ @conn.post(path, body&.compact, headers).body
30
+ end
112
31
 
113
- yield(parse_as, result)
32
+ def put(path, body = nil, headers = nil)
33
+ @conn.post(path, body&.compact, headers).body
114
34
  end
115
35
  end
116
36
  end
@@ -55,13 +55,9 @@ module TridentAssistant
55
55
 
56
56
  def mixin_bot_from_keystore(keystore)
57
57
  keystore = parse_json keystore if keystore.is_a?(String)
58
+ keystore = keystore.with_indifferent_access
58
59
 
59
- MixinBot::API.new(
60
- client_id: keystore["client_id"],
61
- session_id: keystore["session_id"],
62
- pin_token: keystore["pin_token"],
63
- private_key: keystore["private_key"]
64
- )
60
+ MixinBot::API.new **keystore
65
61
  end
66
62
 
67
63
  def parse_metadata(input)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TridentAssistant
4
- VERSION = "0.1.7"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  require "mixin_bot"
4
4
  require "open-uri"
5
+ require 'faraday'
6
+ require 'faraday/multipart'
7
+ require 'faraday/retry'
5
8
 
6
9
  # Trident SDK
7
10
  module TridentAssistant
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trident_assistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-21 00:00:00.000000000 Z
11
+ date: 2023-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixin_bot
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: '1.0'
27
27
  description: A simple program to use Trident NFT
28
28
  email:
29
29
  - an.lee.work@gmail.com
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.3.4
88
+ rubygems_version: 3.4.21
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: A simple program to use Trident NFT