trident_assistant 0.1.3 → 0.1.4

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: 5ca51a3b40da71d8ead06326ccd1377008aafe793e3881b9c4aaede46df73351
4
- data.tar.gz: 9bf39cd480e433eab5443db26c57bec9e7c0445bb57aebdeddc2e2c439de03df
3
+ metadata.gz: f164a9116aa89a445553f7af742157ac0da7670dc436c8235508ff5e4a8030be
4
+ data.tar.gz: e0602539c1087780a03b543c90da70afbae5aced33373eb50339575a733f97e7
5
5
  SHA512:
6
- metadata.gz: 2dd9e5df04ccfb3d41bc4c6b2ce1bc3a8b7f48453d692bff4cae9901e3da1c11fd6c2d2cfe9d5cb8dac8e4601b77bdcaea5a75c167b83622027558bd2a57bcb2
7
- data.tar.gz: 3791ef7f7ec907f6b0f2a9ce807a1a157b92999291f60c99b24fc27f578af1c33751ac1d86a6c6c0143ddcc2b2cfb75300283cd832dc749e9eeb080af45a0890
6
+ metadata.gz: 8c3292e2f06b569a50357d64e0d8811218cdb1911e0c2eb544560c25e64a698f02b758f59a149cad1c5b9d0705bc952b73aaff1c77360ef83379a9217a69f6f2
7
+ data.tar.gz: ed3f043aa8ec27ee9931d41f2becaa031588d208c7a7b142c29db028380939d4a220319b5768a4cb2a912c0051bbae2c1e9ff4601d5f87cec1a4a1d5d1f25bcd
@@ -9,7 +9,7 @@ module TridentAssistant
9
9
 
10
10
  def deposit(collection, token)
11
11
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
12
- collectible = mixin_bot.collectibles(state: :unspent)["data"].find(&->(c) { c["token_id"] == token_id })
12
+ collectible = find_collectible(:unspent, token_id)
13
13
  raise "Unauthorized" if collectible.blank?
14
14
 
15
15
  nfo = MixinBot::Utils::Nfo.new(extra: "deposit".unpack1("H*")).encode.hex
@@ -36,8 +36,8 @@ module TridentAssistant
36
36
 
37
37
  def airdrop(collection, token, **kwargs)
38
38
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
39
- collectible = mixin_bot.collectibles(state: :unspent)["data"].find(&->(c) { c["token_id"] == token_id })
40
- collectible ||= mixin_bot.collectibles(state: :signed)["data"].find(&->(c) { c["token_id"] == token_id })
39
+ collectible = find_collectible(:unspent, token_id)
40
+ collectible ||= find_collectible(:signed, token_id)
41
41
  raise "Cannot find collectible in wallet" if collectible.blank?
42
42
 
43
43
  memo =
@@ -58,8 +58,8 @@ module TridentAssistant
58
58
 
59
59
  def transfer(collection, token, recipient, **_kwargs)
60
60
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
61
- collectible = mixin_bot.collectibles(state: :unspent)["data"].find(&->(c) { c["token_id"] == token_id })
62
- collectible ||= mixin_bot.collectibles(state: :signed)["data"].find(&->(c) { c["token_id"] == token_id })
61
+ collectible = find_collectible(:unspent, token_id)
62
+ collectible ||= find_collectible(:signed, token_id)
63
63
  raise "Cannot find collectible in wallet" if collectible.blank?
64
64
 
65
65
  memo = "TRANSFER"
@@ -75,23 +75,38 @@ module TridentAssistant
75
75
 
76
76
  private
77
77
 
78
+ def find_collectible(state, token_id)
79
+ limit = 500
80
+ offset = ""
81
+
82
+ loop do
83
+ r = mixin_bot.collectibles(state: state, limit: limit, offset: offset)["data"]
84
+ puts "offset: #{offset}, loaded #{r.size} collectibles"
85
+ collectible = r.find(&->(c) { c["token_id"] == token_id })
86
+ break collectible if collectible.present?
87
+
88
+ break if r.size < 500
89
+
90
+ offset = r.last["updated_at"]
91
+ end
92
+ end
93
+
78
94
  def _transfer_nft(collectible, nfo, **kwargs)
79
- tx =
80
- if collectible["state"] == "signed"
81
- collectible["signed_tx"]
82
- else
83
- raw = mixin_bot.build_collectible_transaction(
84
- collectible: collectible,
85
- receivers: kwargs[:receivers],
86
- receivers_threshold: kwargs[:threshold],
87
- nfo: nfo
88
- )
89
- mixin_bot.sign_raw_transaction raw
90
- end
91
-
92
- request = mixin_bot.create_sign_collectible_request tx
93
- sign = mixin_bot.sign_collectible_request request["request_id"], keystore[:pin]
94
- mixin_bot.send_raw_transaction sign["raw_transaction"]
95
+ if collectible["state"] == "signed"
96
+ mixin_bot.send_raw_transaction collectible["signed_tx"]
97
+ else
98
+ raw = mixin_bot.build_collectible_transaction(
99
+ collectible: collectible,
100
+ receivers: kwargs[:receivers],
101
+ receivers_threshold: kwargs[:threshold],
102
+ nfo: nfo
103
+ )
104
+ tx = mixin_bot.sign_raw_transaction raw
105
+
106
+ request = mixin_bot.create_sign_collectible_request tx
107
+ sign = mixin_bot.sign_collectible_request request["request_id"], keystore[:pin]
108
+ mixin_bot.send_raw_transaction sign["raw_transaction"]
109
+ end
95
110
  end
96
111
  end
97
112
  end
@@ -11,7 +11,7 @@ module TridentAssistant
11
11
  desc: "keystore or keystore.json file of Mixin bot"
12
12
  option :keystore, type: :string, aliases: "k", required: true, desc: "keystore or keystore.json file of Mixin bot"
13
13
  def index
14
- r = api.mixin_bot.collectibles state: options[:state]
14
+ r = api.mixin_bot.collectibles state: options[:state], limit: 500
15
15
 
16
16
  log r["data"]
17
17
  end
@@ -87,7 +87,18 @@ module TridentAssistant
87
87
  log UI.fmt("{{v}} airdrop receiver_id: #{receiver_id}")
88
88
  log UI.fmt("{{v}} airdrop start_at: #{start_at}")
89
89
 
90
- r = api.airdrop metadata.collection["id"], metadata.token["id"], receiver_id: receiver_id, start_at: start_at
90
+ attempt = 0
91
+ r =
92
+ begin
93
+ attempt += 1
94
+ api.airdrop metadata.collection["id"], metadata.token["id"], receiver_id: receiver_id, start_at: start_at
95
+ rescue Errno::ECONNRESET, OpenSSL::SSL::SSLError, MixinBot::HttpError => e
96
+ log UI.fmt("{{x}} #{e.inspect}")
97
+ log UI.fmt("Retrying #{attempt} times...")
98
+ sleep 0.5
99
+ retry
100
+ end
101
+
91
102
  log r["data"]
92
103
  data["_airdrop"] ||= {}
93
104
  data["_airdrop"]["hash"] = r["data"]["hash"]
@@ -26,9 +26,20 @@ module TridentAssistant
26
26
  files.each do |file|
27
27
  log "-" * 80
28
28
  log UI.fmt("{{v}} found #{file}")
29
- minted.push(file) if _mint(file)
30
- rescue TridentAssistant::Utils::Metadata::InvalidFormatError, JSON::ParserError, Client::RequestError,
31
- MixinBot::Error, RuntimeError => e
29
+ attempt = 0
30
+ success =
31
+ begin
32
+ attempt += 1
33
+ _mint file
34
+ rescue Errno::ECONNRESET, OpenSSL::SSL::SSLError, MixinBot::HttpError, TridentAssistant::Client::HttpError,
35
+ TridentAssistant::Client::RequestError, MixinBot::RequestError => e
36
+ log UI.fmt("{{x}} #{e.inspect}")
37
+ log UI.fmt("Retrying #{attempt} times...")
38
+ sleep 0.5
39
+ retry
40
+ end
41
+ minted.push(file) if success
42
+ rescue TridentAssistant::Utils::Metadata::InvalidFormatError, JSON::ParserError, RuntimeError => e
32
43
  log UI.fmt("{{x}} #{file} failed: #{e.inspect}")
33
44
  next
34
45
  end
@@ -76,33 +87,28 @@ module TridentAssistant
76
87
  memo = api.mixin_bot.nft_memo metadata.collection[:id], metadata.token[:id].to_i, metadata.metahash
77
88
 
78
89
  data["_mint"]["trace_id"] = trace_id
79
- loop do
90
+ begin
80
91
  payment =
81
- begin
82
- api.mixin_bot.create_multisig_transaction(
83
- api.keystore[:pin],
84
- {
85
- asset_id: TridentAssistant::Utils::MINT_ASSET_ID,
86
- trace_id: trace_id,
87
- amount: TridentAssistant::Utils::MINT_AMOUNT,
88
- memo: memo,
89
- receivers: TridentAssistant::Utils::NFO_MTG[:members],
90
- threshold: TridentAssistant::Utils::NFO_MTG[:threshold]
91
- }
92
- )
93
- rescue MixinBot::InsufficientPoolError, MixinBot::HttpError => e
94
- log UI.fmt("{{x}} #{e.inspect}")
95
- log "Retrying to pay..."
96
- sleep 1
97
- nil
98
- end
99
-
100
- next if payment.blank? || payment["errors"].present?
92
+ api.mixin_bot.create_multisig_transaction(
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
+ }
102
+ )
101
103
 
102
104
  log UI.fmt("{{v}} NFT mint payment paid: #{payment["data"]}")
103
105
  data["_mint"]["token_id"] = token_id
104
106
  log UI.fmt("{{v}} NFT successfully minted")
105
- break
107
+ rescue MixinBot::InsufficientPoolError, MixinBot::HttpError => e
108
+ log UI.fmt("{{x}} #{e.inspect}")
109
+ log "Retrying to pay..."
110
+ sleep 1
111
+ retry
106
112
  end
107
113
 
108
114
  data.dig("_mint", "token_id").present?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TridentAssistant
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
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.3
4
+ version: 0.1.4
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-04-25 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixin_bot