Skip to content

feat: add --csv option to the lotus send cmd#12892

Merged
rjan90 merged 7 commits intomasterfrom
phi/send-csv-option
Feb 14, 2025
Merged

feat: add --csv option to the lotus send cmd#12892
rjan90 merged 7 commits intomasterfrom
phi/send-csv-option

Conversation

@rjan90
Copy link
Copy Markdown
Contributor

@rjan90 rjan90 commented Feb 11, 2025

Related Issues

Closes #12890

Proposed Changes

  • Add --csv option to the lotus send cmd.

Additional Info

Took it for a spin in testnet:

  1. Created a test.csv file:
Recipient,FIL,Method,Params
t1f4ofu37insbsuiezckfsiuore45ilgvzrygvoia,100,0,nil
t3xhvabu2hvh3yfwymc2z4swdu3vjxgh5oq6deopcmfmyw5rj76pmwhmhxxhbjxblkk34dp52jewrxfe7tn5oq,100,0,nil
t410fb5gax57j2p57kfzkwy24an2ciqnragjiw45yw3i,100,0,nil
  1. Used the --csv option in lotus send:
Sending messages from: t3wmauwt3ekfjrnvmlsqkjf5cvslhu7zdwkaz73uj4ft77mamerf7xccfpqey32s6axdvbutyy4pgyxqfsb6oq
Sent message 0: bafy2bzacebjbmy57tduppwk3uszqlw5gbauyjibq4sifgn2fa2qxvnqtb5lai
Sent message 1: bafy2bzaced72aji46lpjwoljdca3wv5ysjlxxcll372vl2arhuzkmoj7vidry
Sent message 2: bafy2bzacedta7rg7dzlrhi7jrjo6lrevjda2tvepp56tszzzxk5cp2w4hxqha
  1. Confirmed testFIL got sent to the addresses:
lotus wallet list
Address                                                                                 Balance                          Nonce  Default  
t1f4ofu37insbsuiezckfsiuore45ilgvzrygvoia                                               100 FIL                          0               
t3wmauwt3ekfjrnvmlsqkjf5cvslhu7zdwkaz73uj4ft77mamerf7xccfpqey32s6axdvbutyy4pgyxqfsb6oq  49997199.999547879770983812 FIL  20     X        
t3xhvabu2hvh3yfwymc2z4swdu3vjxgh5oq6deopcmfmyw5rj76pmwhmhxxhbjxblkk34dp52jewrxfe7tn5oq  100 FIL                          0               
t410fb5gax57j2p57kfzkwy24an2ciqnragjiw45yw3i                                            100 FIL                          0            
  1. Did a test by using the --from option to specify sending address:
lotus send --csv test.csv --from t3sdjzgejq257sqcpt5mijdvyzddd5tdsaky372caq6mfp66qelkuwrl3foj4pniivgz53c2o7l6n2qcbpjgca
Sending messages from: t3sdjzgejq257sqcpt5mijdvyzddd5tdsaky372caq6mfp66qelkuwrl3foj4pniivgz53c2o7l6n2qcbpjgca
Sent message 0: bafy2bzaceda7aqsiiqa6kstereywxqxw4lg55vkftoufepm2at4xmg2hxnqhm
Sent message 1: bafy2bzaceak6wx3pepsyf65nxylfygkk3wkitqrahzboc7h5hdkwsvixyvsku
Sent message 2: bafy2bzacectrc36grvhnvbhrt2ep6q45xvq4brvmjx3et2m7bkalidpwkk5km
  1. Confirming testFIL got sent from the --from address
lotus wallet list
Address                                                                                 Balance                          Nonce  Default  
t1f4ofu37insbsuiezckfsiuore45ilgvzrygvoia                                               200 FIL                          0               
t3sdjzgejq257sqcpt5mijdvyzddd5tdsaky372caq6mfp66qelkuwrl3foj4pniivgz53c2o7l6n2qcbpjgca  9699.999999556644712094 FIL      3               
t3wmauwt3ekfjrnvmlsqkjf5cvslhu7zdwkaz73uj4ft77mamerf7xccfpqey32s6axdvbutyy4pgyxqfsb6oq  49987199.999547143538592672 FIL  21     X        
t3xhvabu2hvh3yfwymc2z4swdu3vjxgh5oq6deopcmfmyw5rj76pmwhmhxxhbjxblkk34dp52jewrxfe7tn5oq  200 FIL                          0               
t410fb5gax57j2p57kfzkwy24an2ciqnragjiw45yw3i                                            200 FIL                          0          

Checklist

Before you mark the PR ready for review, please make sure that:

@rjan90 rjan90 changed the title feat: add --csv option to the lotus send cmd. feat: add --csv option to the lotus send cmd Feb 11, 2025
@rjan90
Copy link
Copy Markdown
Contributor Author

rjan90 commented Feb 12, 2025

I wonder if it is also worth adding a funds check before processing the CSV transactions to prevent partial failures? Currently it will fail midway through if the wallet does not have enough funds:

lotus send --csv test.csv --from t3sdjzgejq257sqcpt5mijdvyzddd5tdsaky372caq6mfp66qelkuwrl3foj4pniivgz53c2o7l6n2qcbpjgca
Sending messages from: t3sdjzgejq257sqcpt5mijdvyzddd5tdsaky372caq6mfp66qelkuwrl3foj4pniivgz53c2o7l6n2qcbpjgca
Sent message 0: bafy2bzacecpbdkwnwglbr4biv4tk4pngnfgqdlrhcdvyqlb5d4enadloioj4o
ERROR: sending message for row 1: publishing message: estimating gas: message execution failed: exit SysErrInsufficientFunds(6), reason: message failed with backtrace:
--> caused by: send::send -- sender does not have funds to transfer (balance 99.999999262482484072, transfer 100.0) (5: insufficient funds)
 (RetCode=6)

And also, to reduce duplication, should I remove the send-csv cmd in lotus-shed? Or should we warn that it is going to be deprecated in lotus-shed soon, and that tooling should change to lotus send --csv?

feat: add --csv flag to lotus send
chore: make gen and make docsgen-cli
chore: update changelog
@rjan90 rjan90 force-pushed the phi/send-csv-option branch from d52a7ac to d5e071d Compare February 12, 2025 08:55
@rjan90 rjan90 marked this pull request as ready for review February 12, 2025 08:56
Comment thread cli/send.go
Comment thread cli/send.go Outdated
@rvagg
Copy link
Copy Markdown
Member

rvagg commented Feb 13, 2025

  1. Yes a funds check might be a good idea, since you have the sender address handy you can easily look at its balance, plus if you take the approach I outlined about accumulating SendParams then you can also accumulate a total. Probably not worth factoring in gas to that I suppose, just balance should be OK 🤷.
  2. Just remove it from shed, it's not an "official" tool and this should replace it easily enough.

rjan90 and others added 3 commits February 13, 2025 08:29
Co-authored-by: Rod Vagg <rod@vagg.org>
feat(cli): add two-pass CSV send with balance check
refactor: remove send-csv from lotus-shed
@rjan90
Copy link
Copy Markdown
Contributor Author

rjan90 commented Feb 13, 2025

Pushed the two-pass CSV send, and balance check here: fcad102, and removed the lotus-shed send-civ cmd here: 850127c

Additionally did some other manual tests in a dev-net:

  1. Retrying sends with the new two-pass logic:
cat test_send.csv
Recipient,FIL,Method,Params
t1b7calb236rh2jqoqkrmtlsvwkit3zbue6txnf3q,100,0,nil
t3wilwypcuzmg6hagkjcbofqnsein5zkrozk4qbp63t45ksm5bqvyypiuulrcjwnkntlbcigeddcpo7z7as7pq,100,0,nil
t410fscmqjpk4l26vrgnm5ouq2r6szmer7bb6luywdvi,100,0,nil

Normal send:

lotus send --csv /Users/phi/lotus/test_send.csv
Sending messages from: t3wo7hoioxkgtterimsmmujxo2pellmt2vtxzjljsqcgouiptce6g24a2evc6m7le6ghakihjzqvab5wshnrxa
Sent message 0: bafy2bzacedjwiarnrqpil5focgohn6fbayuvyluwjkoyr2bpbkvivgd6at6qw
Sent message 1: bafy2bzacect4hjios3aq3kzkccws55wbf2ve2swe2vzl46qszsksi3hjmmxsw
Sent message 2: bafy2bzacedm62cs5kqaqixiotlxnbk5jcdlbnoogzvbgrmmbche4oobwzes6e

Send by specifying --from address:

lotus send --from t1awilxuksvbwhvtk5ndu7t2ypfwqpnywykgekg4q --csv /Users/phi/lotus/test_send.csv
Sending messages from: t1awilxuksvbwhvtk5ndu7t2ypfwqpnywykgekg4q
Sent message 0: bafy2bzacedp2obalfhpy55we27c4xarybvb2fclgntwnmfcsk7rdibwzvgl3s
Sent message 1: bafy2bzacedsjl5sxeev4kmijbpie7c272ysuztyezxgmxmh3737m7t322gmf2
Sent message 2: bafy2bzacecziqcqtp3sc5fixals7pacpzezidnwnshlru5v47q7vx7wnj2jos
  1. Check that insufficient funds in an address fails:
lotus send --from t1awilxuksvbwhvtk5ndu7t2ypfwqpnywykgekg4q --csv /Users/phi/lotus/test_send.csv
Sending messages from: t1awilxuksvbwhvtk5ndu7t2ypfwqpnywykgekg4q
ERROR: insufficient funds: need 300 FIL FIL, have 99.999999509406890284 FIL FIL
  1. Check that wrong amount of fields and headers in the csv-file fails:

Wrong amount of headers:

cat wrong_headers.csv
Recipient,FIL,Method,Params,Extra
t1b7calb236rh2jqoqkrmtlsvwkit3zbue6txnf3q,100,0,nil,extra
t3wilwypcuzmg6hagkjcbofqnsein5zkrozk4qbp63t45ksm5bqvyypiuulrcjwnkntlbcigeddcpo7z7as7pq,100,0,nil,extra
lotus send --csv /Users/phi/lotus/wrong_headers.csv
Sending messages from: t3wo7hoioxkgtterimsmmujxo2pellmt2vtxzjljsqcgouiptce6g24a2evc6m7le6ghakihjzqvab5wshnrxa
ERROR: expected header row to be "Recipient,FIL,Method,Params"

Wrong amount of fields:

cat wrong_fields.csv
Recipient,FIL,Method,Params
t1b7calb236rh2jqoqkrmtlsvwkit3zbue6txnf3q,100,0,nil,extra
t3wilwypcuzmg6hagkjcbofqnsein5zkrozk4qbp63t45ksm5bqvyypiuulrcjwnkntlbcigeddcpo7z7as7pq,100,0,nil,extra
lotus send --csv /Users/phi/lotus/wrong_fields.csv
Sending messages from: t3wo7hoioxkgtterimsmmujxo2pellmt2vtxzjljsqcgouiptce6g24a2evc6m7le6ghakihjzqvab5wshnrxa
ERROR: read csv: record on line 2: wrong number of fields

Comment thread cli/send.go Outdated
Copy link
Copy Markdown
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

Co-authored-by: Rod Vagg <rod@vagg.org>
@rjan90 rjan90 merged commit 97dc186 into master Feb 14, 2025
@rjan90 rjan90 deleted the phi/send-csv-option branch February 14, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ☑️ Done (Archive)

Development

Successfully merging this pull request may close these issues.

Add --csv option to lotus send command

2 participants