Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

cli: Lookup address by account name, add support for test accounts #1038

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

matevz
Copy link
Member

@matevz matevz commented Jul 8, 2022

Fixes #891.

This PR adds the following to oasis accounts command:

  • if address equals account name in the wallet, it returns the address corresponding to the account
  • if address starts with test:, it finds the corresponding testing account (Alice, Bob, Charlie etc.) and returns the testing account address
  • if --account value starts with test:, it takes the testing account key to sign the transaction
  • updates minimal-runtime docs accordingly
  • fixes crash when calling oasis accounts withdraw <amount> [to] without to parameter

Example usage:

$ oasis accounts show mywallet
Address: oasis1qqgwegnh3h6p0828npmqed0f243fd9pyhcgmmmt4
Nonce: 0

=== CONSENSUS LAYER (testnet) ===
  Total: 0.0 TEST
  Available: 0.0 TEST

$ oasis accounts show test:bob
Address: oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx
Nonce: 0

=== CONSENSUS LAYER (testnet) ===
  Total: 0.0 TEST
  Available: 0.0 TEST

$ oasis accounts transfer 1 test:alice --paratime emerald --account test:dave
You are about to sign the following transaction:
{
  "v": 1,
  "call": {
    "method": "accounts.Transfer",
    "body": "omJ0b1UA84957B5s/pe0/gbHiYtSqPrbR4NmYW1vdW50gkgN4Lazp2QAAEA="
  },
  "ai": {
    "si": [
      {
        "address_spec": {
          "signature": {
            "secp256k1eth": "AwF6GNjbybMzhi3XRj5R1oTiMMkO1nAwB7NZAlH1X4BE"
          }
        },
        "nonce": 27
      }
    ],
    "fee": {
      "amount": {
        "Amount": "232100000000000",
        "Denomination": ""
      },
      "gas": 2321
    }
  }
}

Account:  test:dave
Network:  testnet
Paratime: emerald
? Sign this transaction? (y/N)

$ oasis accounts withdraw 1 test:erin --paratime emerald --account test:alice
Error: test account 'erin' (oasis1qqcd0qyda6gtwdrfcqawv3s8cr2kupzw9v967au6) will not be able to sign transactions on consensus layer

$ oasis accounts withdraw 1 test:bob --paratime emerald --account test:alice
You are about to sign the following transaction:
{
  "v": 1,
  "call": {
    "method": "consensus.Withdraw",
    "body": "omJ0b1UAyND0Wds45cwxynfmbSxEVty+tQJmYW1vdW50gkgN4Lazp2QAAEA="
  },
  "ai": {
    "si": [
      {
        "address_spec": {
          "signature": {
            "ed25519": "NcPzNW3YU2T+ugNUtUWtoQnRvbOL9dYSaBfbjHLP1pE="
          }
        },
        "nonce": 13
      }
    ],
    "fee": {
      "amount": {
        "Amount": "1131500000000000",
        "Denomination": ""
      },
      "gas": 11315,
      "consensus_messages": 1
    }
  }
}

Account:  test:alice
Network:  testnet
Paratime: emerald
? Sign this transaction? (y/N)

@matevz matevz added the c:cli label Jul 8, 2022
@codecov
Copy link

codecov bot commented Jul 8, 2022

Codecov Report

Merging #1038 (7cec9c2) into main (a1253bf) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1038      +/-   ##
==========================================
+ Coverage   67.96%   68.00%   +0.03%     
==========================================
  Files         128      128              
  Lines       11017    11030      +13     
==========================================
+ Hits         7488     7501      +13     
  Misses       3497     3497              
  Partials       32       32              
Impacted Files Coverage Δ
client-sdk/go/testing/testing.go 95.23% <ø> (ø)
client-sdk/go/helpers/address.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1253bf...7cec9c2. Read the comment docs.

@matevz matevz force-pushed the matevz/feature/cli-address-shortcuts branch from 38647bb to f640207 Compare July 8, 2022 16:29
cli/cmd/wallet.go Outdated Show resolved Hide resolved
cli/cmd/common/wallet.go Outdated Show resolved Hide resolved
cli/cmd/common/wallet.go Outdated Show resolved Hide resolved
cli/cmd/common/wallet.go Outdated Show resolved Hide resolved
cli/cmd/common/wallet.go Outdated Show resolved Hide resolved
cli/cmd/accounts.go Outdated Show resolved Hide resolved
cli/cmd/common/selector.go Outdated Show resolved Hide resolved
cli/wallet/test/test.go Show resolved Hide resolved
client-sdk/go/helpers/address.go Outdated Show resolved Hide resolved
client-sdk/go/testing/testing.go Outdated Show resolved Hide resolved
@matevz matevz force-pushed the matevz/feature/cli-address-shortcuts branch 2 times, most recently from b12f0f4 to 4e19721 Compare July 12, 2022 12:19
@matevz matevz requested a review from kostko July 12, 2022 12:19
@matevz matevz force-pushed the matevz/feature/cli-address-shortcuts branch from 4e19721 to b734d8f Compare July 12, 2022 12:20
Copy link
Member

@kostko kostko left a comment

Choose a reason for hiding this comment

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

Nice, just some minor things.

client-sdk/go/helpers/address.go Show resolved Hide resolved
client-sdk/go/helpers/address_test.go Show resolved Hide resolved
@matevz matevz force-pushed the matevz/feature/cli-address-shortcuts branch from b734d8f to 4abc734 Compare July 12, 2022 14:16
@matevz matevz force-pushed the matevz/feature/cli-address-shortcuts branch from 4abc734 to 7cec9c2 Compare July 12, 2022 14:20
@matevz matevz merged commit 4664a17 into main Jul 12, 2022
@matevz matevz deleted the matevz/feature/cli-address-shortcuts branch July 12, 2022 14:54
tjanez pushed a commit to oasisprotocol/cli that referenced this pull request Sep 20, 2022
tjanez pushed a commit to oasisprotocol/cli that referenced this pull request Oct 11, 2022
tjanez pushed a commit to oasisprotocol/cli that referenced this pull request Oct 11, 2022
tjanez pushed a commit to oasisprotocol/cli that referenced this pull request Oct 11, 2022
tjanez pushed a commit to oasisprotocol/cli that referenced this pull request Oct 11, 2022
tjanez pushed a commit to oasisprotocol/cli that referenced this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: Add support for referencing wallets in addresses
2 participants