Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: support json output in the boost wallet command #603

Merged
merged 1 commit into from
Jun 21, 2022

Conversation

nicobao
Copy link
Contributor

@nicobao nicobao commented Jun 19, 2022

Relates to #469

List of commands (boost --json wallet <command>) to implement json support for:

  • new
  • list
  • balance
  • export
  • import
  • default/get-default
  • set-default (no output on the first place)
  • delete (no output on the first place)

@nicobao
Copy link
Contributor Author

nicobao commented Jun 19, 2022

Errors are printed in plaintext rather than wrapped in a JSON (field "error"). I followed the same behavior as with the other commands.

Current state of progress [final - PR ready for review]:

new:

nicolas@localhost:~/nicobao/boost$ boost --json wallet new
{
  "newAddress": "t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi"
}

list:

nicolas@localhost:~/nicobao/boost$ boost --json wallet list
[
  {
    "address": "t1d4kjp22hziwmufsylcccuxlr6t2idwjg47jcj5y",
    "balance": 10000000000000000000,
    "marketAvail": 0,
    "marketLocked": 0,
    "nounce": 0
  },
  {
    "address": "t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly",
    "balance": 0,
    "nounce": 0
  },
  {
    "address": "t1njjqa7eu5hjbb2ak35kfikpieb36aojlzyhhhbi",
    "balance": 0,
    "nounce": 0
  },
  {
    "address": "t1r4jcxgbytp63tzdyh34wi6qo2rwrfrdy5emo3oy",
    "balance": 0,
    "nounce": 0
  },
  {
    "address": "t1vjp5cqffmx4dns7dxfuluwo2rfcuvi3jvpacjfy",
    "balance": 0,
    "nounce": 0
  },
  {
    "address": "t1xfeixf3bodntjygx7jrrdhispxdzlzl335gawji",
    "balance": 0,
    "nounce": 0
  },
  {
    "address": "t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi",
    "balance": 10000000000000000000,
    "marketAvail": 0,
    "marketLocked": 0,
    "nounce": 0
  },
  {
    "address": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga",
    "balance": 98999999999080654526,
    "default": "X",
    "marketAvail": 1000000000000000000,
    "marketLocked": 0,
    "nounce": 1
  }
]

balance:

nicolas@localhost:~/nicobao/boost$ boost --json wallet balance
{
  "balance": 5000000000000000000
}
nicolas@localhost:~/nicobao/boost$ boost --json wallet balance t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi
{
  "balance": 0,
  "warning": "may display 0 if chain sync in progress"
}

export:

nicolas@localhost:~/nicobao/boost$ boost --json wallet export t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga
{
  "exportedKey": "7b2254797065223a22626c73222c22507269766174654b6579223a2279655954574156556f39545648696d426d71547865344a714472473366352b6c41316f4a507a623232306b3d227d"
}
nicolas@localhost:~/nicobao/boost$ boost --json wallet export
Error: must specify key to export
nicolas@localhost:~/nicobao/boost$ boost --json wallet export dkjf
Error: unknown address network

import:

nicolas@localhost:~/nicobao/boost$ boost --json wallet import ./private.key
{
  "importedAddress": "t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly"
}
nicolas@localhost:~/nicobao/boost$ boost --json wallet import 
Enter private key: jdksjfkdlwsf
Error: encoding/hex: invalid byte: U+006A 'j'
nicolas@localhost:~/nicobao/boost$ boost --json wallet import ./private.key
Error: saving to keystore: checking key before put 'wallet-t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga': key already exists
nicolas@localhost:~/nicobao/boost$ boost --json wallet import 7b2254797065223a22626c73222c22507269766174654b6579223a2279655954574156556f39545648696d426d71547865344a714472473366352b6c41316f4a507a623232306b3d227d
Error: open 7b2254797065223a22626c73222c22507269766174654b6579223a2279655954574156556f39545648696d426d71547865344a714472473366352b6c41316f4a507a623232306b3d227d: no such file or directory

default/get-default:

nicolas@localhost:~/nicobao/boost$ boost --json wallet default
{
  "defaultAddress": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga"
}
nicolas@localhost:~/nicobao/boost$ boost --json wallet get-default
{
  "defaultAddress": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga"
}

@nicobao nicobao changed the title DRAFT: feat: support json output to the boost wallet command DRAFT: feat: support json output in the boost wallet command Jun 19, 2022
@nicobao nicobao force-pushed the feat/json-cli-wallet/469 branch 4 times, most recently from c2011a1 to 9a54a91 Compare June 19, 2022 19:06
@nicobao nicobao changed the title DRAFT: feat: support json output in the boost wallet command feat: support json output in the boost wallet command Jun 19, 2022
Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

This looks great 👍

I added a couple of minor suggestions, but over all LGTM 👍

Thanks for adding the output of each command, it helps a lot with reviewing 🙏

@dirkmc
Copy link
Contributor

dirkmc commented Jun 20, 2022

Errors are printed in plaintext rather than wrapped in a JSON (field "error"). I followed the same behavior as with the other commands

I think it would make more sense to print them out as JSON. Because probably when the --json flag is supplied to these commands, it's because the command is being called from a script which expects JSON as output.

@nicobao
Copy link
Contributor Author

nicobao commented Jun 20, 2022

I agree with you. I initially did it and then rolled back my changes to stay consistent with the behaviour of the other commands.
For example in boost deal, errors aren't wrapped in JSON but printed as plain text.

I think it's better to fix this behaviour in a separate PR for all the commands.

But I can do this in this PR. Whatever you prefer works for me! :)

@dirkmc
Copy link
Contributor

dirkmc commented Jun 20, 2022

Makes sense, let's do it in a follow-up PR.
Thank you 🙏

@nicobao nicobao force-pushed the feat/json-cli-wallet/469 branch from 9a54a91 to 34dc67e Compare June 21, 2022 10:23
@nicobao
Copy link
Contributor Author

nicobao commented Jun 21, 2022

I just pushed the suggested changes.
Here are the new outputs.

boost --json wallet new:

nicolas@localhost:~/nicobao/boost$ boost --json wallet new
{
  "address": "t12gsnatmu224p3ebp2l36jxfsd4rgnixuaoctzya"
}

boost --json wallet list:

nicolas@localhost:~/nicobao/boost$ boost --json wallet list
[
  {
    "address": "t1d4kjp22hziwmufsylcccuxlr6t2idwjg47jcj5y",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1gvk5kxmtyqpluu523xz3efz6x2muodrn3ep5x6q",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1njjqa7eu5hjbb2ak35kfikpieb36aojlzyhhhbi",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1r4jcxgbytp63tzdyh34wi6qo2rwrfrdy5emo3oy",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1vjp5cqffmx4dns7dxfuluwo2rfcuvi3jvpacjfy",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1xfeixf3bodntjygx7jrrdhispxdzlzl335gawji",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1ysah3vqiokryvtvralxrrb7r5epq7bxaosolq2a",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi",
    "balance": 0,
    "nonce": 0
  },
  {
    "address": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga",
    "balance": 10000000000000000000,
    "default": "X",
    "market": {
      "available": 0,
      "locked": 0
    },
    "nonce": 0
  }
]

boost wallet list:

nicolas@localhost:~/nicobao/boost$ boost wallet list
Address                                                                                 Balance  Market(Avail)  Market(Locked)  Nonce  Default  
t1d4kjp22hziwmufsylcccuxlr6t2idwjg47jcj5y                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1gvk5kxmtyqpluu523xz3efz6x2muodrn3ep5x6q                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1njjqa7eu5hjbb2ak35kfikpieb36aojlzyhhhbi                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1r4jcxgbytp63tzdyh34wi6qo2rwrfrdy5emo3oy                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1vjp5cqffmx4dns7dxfuluwo2rfcuvi3jvpacjfy                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1xfeixf3bodntjygx7jrrdhispxdzlzl335gawji                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1ysah3vqiokryvtvralxrrb7r5epq7bxaosolq2a                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
                                                                                                 0 FIL                                          
                                                                                                                0 FIL                           
t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga                                                          
                                                                                        10 FIL                                                  
                                                                                                                                0               
                                                                                                                                       X  

balance:

nicolas@localhost:~/nicobao/boost$ boost --json wallet balance
{
  "balance": 10000000000000000000
}

export:

nicolas@localhost:~/nicobao/boost$ boost --json wallet export t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga
{
  "key": "7b2254797065223a22626c73222c22507269766174654b6579223a2279655954574156556f39545648696d426d71547865344a714472473366352b6c41316f4a507a623232306b3d227d"
}

import:

nicolas@localhost:~/nicobao/boost$ boost --json wallet import ./private.key
{
  "address": "t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly"
}

default/get-default:

nicolas@localhost:~/nicobao/boost$ boost --json wallet default
{
  "address": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga"
}

@nicobao
Copy link
Contributor Author

nicobao commented Jun 21, 2022

If it works for you and you merge it, I'll open a new PR for wrapping the errors in all the commands.
I updated the first post to avoid closing the issue on merging the PR.

@dirkmc
Copy link
Contributor

dirkmc commented Jun 21, 2022

This looks great, thanks!

One more suggestion for the output:
Can we change "default": "X" to "default": true here, and add "default": false for non-default wallets:

  {
    "address": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga",
    "balance": 10000000000000000000,
    "default": "X",
    "market": {
      "available": 0,
      "locked": 0
    },
    "nonce": 0
  }

@nicobao nicobao force-pushed the feat/json-cli-wallet/469 branch from 34dc67e to 5229df0 Compare June 21, 2022 13:16
@nicobao
Copy link
Contributor Author

nicobao commented Jun 21, 2022

This looks great, thanks!

One more suggestion for the output: Can we change "default": "X" to "default": true here, and add "default": false for non-default wallets:

  {
    "address": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga",
    "balance": 10000000000000000000,
    "default": "X",
    "market": {
      "available": 0,
      "locked": 0
    },
    "nonce": 0
  }

I implemented your suggested changes.
Here it is the latest output:

nicolas@localhost:~/nicobao/boost$ boost wallet list
Address                                                                                 Balance  Market(Avail)  Market(Locked)  Nonce  Default  
t12gsnatmu224p3ebp2l36jxfsd4rgnixuaoctzya                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1d4kjp22hziwmufsylcccuxlr6t2idwjg47jcj5y                                                                                                       
t1gvk5kxmtyqpluu523xz3efz6x2muodrn3ep5x6q                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1njjqa7eu5hjbb2ak35kfikpieb36aojlzyhhhbi                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
                                                                                                                                0               
t1r4jcxgbytp63tzdyh34wi6qo2rwrfrdy5emo3oy                                                                                                       
                                                                                        0 FIL                                                   
t1vjp5cqffmx4dns7dxfuluwo2rfcuvi3jvpacjfy                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1xfeixf3bodntjygx7jrrdhispxdzlzl335gawji                                                                                                       
t1ysah3vqiokryvtvralxrrb7r5epq7bxaosolq2a                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi                                                                                                       
                                                                                        0 FIL                                                   
                                                                                                                                0               
                                                                                        10 FIL                                                  
                                                                                                                                0               
                                                                                                                                       X        
                                                                                                 0 FIL                                          
                                                                                                                0 FIL                           
t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga                                                          
nicolas@localhost:~/nicobao/boost$ boost --json wallet list
[
  {
    "address": "t12gsnatmu224p3ebp2l36jxfsd4rgnixuaoctzya",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1d4kjp22hziwmufsylcccuxlr6t2idwjg47jcj5y",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1gvk5kxmtyqpluu523xz3efz6x2muodrn3ep5x6q",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1m6n4xcslethwc67p3kwr4tb7iutw226c3z2skly",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1njjqa7eu5hjbb2ak35kfikpieb36aojlzyhhhbi",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1r4jcxgbytp63tzdyh34wi6qo2rwrfrdy5emo3oy",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1vjp5cqffmx4dns7dxfuluwo2rfcuvi3jvpacjfy",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1xfeixf3bodntjygx7jrrdhispxdzlzl335gawji",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1ysah3vqiokryvtvralxrrb7r5epq7bxaosolq2a",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t1yxgm5zm774aojjzttaeqbxpr37jmvzk3c36vbqi",
    "balance": 0,
    "default": false,
    "nonce": 0
  },
  {
    "address": "t3u4btxwh6cg3qhjji7tql4l5eieimmxybxyqpuzdwqoolpp6wvegzfk2tyiylwzjk3zuvymffejb2e4ic3oga",
    "balance": 10000000000000000000,
    "default": true,
    "market": {
      "available": 0,
      "locked": 0
    },
    "nonce": 0
  }
]

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

Great work, thanks!

@dirkmc dirkmc merged commit 5c52ea1 into filecoin-project:main Jun 21, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants