Created
June 28, 2022 22:09
-
-
Save xinaxu/312f48e371dba077101de3b31ac89850 to your computer and use it in GitHub Desktop.
Example script to auto import deals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'jimson' | |
## IP/Port/Token for lotus-miner | |
ip = "127.0.0.1" | |
port = "2345" | |
token = "eyJ..." | |
## Only handle deals sent from this client | |
client = "f1ws3n5tuxtyg26lraqkjirz7qon7y7ckju7hhmii" | |
## URL prefix to download the data | |
url = "http://d.techgreedy.net" | |
client = Jimson::Client.new("http://#{ip}:#{port}/rpc/v0", { :Authorization => 'Bearer ' + token}, 'Filecoin.', timeout: 600) | |
deals = client.MarketListIncompleteDeals() | |
deals.each do |deal| | |
# Only handle DealStateAwaiting | |
next if deal['State'] != 18 | |
next if deal['Proposal']['Client'] != client | |
# Get proposal cid | |
proposal = deal['ProposalCid']['/'] | |
# Get data cid | |
data_cid = deal['Ref']['Root']['/'] | |
# Download the car file | |
system("wget #{url}/#{data_cid}.car") | |
# Import the deal with command line | |
system("lotus-miner storage-deals import-data #{proposal} `pwd`/#{data_cid}.car") | |
# Or Import the deal with API | |
# client.MarketImportDealData({'/' => proposal}, File.join(Dir.pwd, "#{data_cid}.car")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment