Skip to content

Instantly share code, notes, and snippets.

@xinaxu
Created June 28, 2022 22:09
Show Gist options
  • Save xinaxu/312f48e371dba077101de3b31ac89850 to your computer and use it in GitHub Desktop.
Save xinaxu/312f48e371dba077101de3b31ac89850 to your computer and use it in GitHub Desktop.
Example script to auto import deals
#!/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