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

Add support for contract id alias and key name to stellar snapshot create. #1662

Merged
merged 5 commits into from
Oct 10, 2024

Conversation

fnando
Copy link
Member

@fnando fnando commented Oct 8, 2024

What

Contract aliasing

Before:

$ stellar snapshot create --address hello --output json --out snapshot.json --network testnet
error: invalid value 'hello' for '--address <ADDRESS>': xdr value invalid

For more information, try '--help'.

After:

$ stellar contract alias ls
ℹ️ Aliases available for network 'Test SDF Network ; September 2015'
hello: CBFPWZNGSIHLC4ZJ4SVPS4CXLH7YQJNCNRQN5EAH5AS7B44BKN4ELEQB


$ stellar snapshot create --address hello --output json --out snapshot.json --network testnet
🌎 Downloading history https://history.stellar.org/prd/core-testnet/core_testnet_001/.well-know
🌎 Downloaded history https://history.stellar.org/prd/core-testnet/core_testnet_001/.well-known/stellar-history.json
ℹ️ Ledger: 345919
ℹ️ Network Passphrase: Test SDF Network ; September 2015
ℹ️ Network id: cee0302d59844d32bdca915c8203dd44b33fbb7edc19051ea37abedf28ecd472
ℹ️ Searching for 0 accounts, 1 contracts, 0 wasms
🔎 Searching bucket 0 3d0c5c771474d78b0c487fc318790b6c11778b4f0fe01b61e606be63a7bfdbb5 (1.0 KB)
🔎 Searching bucket 1 480f2887554305f8784cae7c7f61c6a44a8afa05a5de9b364b770486789cd75a (968 B)
🔎 Searching bucket 2 8d43c5813303a833212ddac9b0ecae09143e2c45cfd9c23d71baf612c6eba85a (1.5 KB)
🔎 Searching bucket 3 cf0741d8d0fd16e7db269e517d7b07c36a7ed008a2556f938d0f74f5569d5a3b (12.6 KB)
🔎 Searching bucket 4 a0ff94130d91984fd414eda7c9d8894412da54a8b63c302307bfb37d8a72df93 (8.1 KB)
🔎 Searching bucket 5 749c9da08b93334df184ce6ab138c2f104ddd6c922c2a57eabc3935df55fb94b (14.3 KB)
🔎 Searching bucket 6 df1eb96bfee2995c3f7a90d960a8c590cb651f4a3151603902abd6f90345d11d (14.7 KB)
🔎 Searching bucket 7 b9f507695fddbbde53ede71c0d591b3ac728ee236addef6044cafcf256fc7049 (41.3 KB)
🔎 Searching bucket 8 70dc0b5cba3338efcda81eb334210bc19c31941af24765ea9bcd246775c78ed2 (233.6 KB)
🔎 Searching bucket 9 ea3f2b433f40d11c7b0ccc17b134673e956b6ed5b1e02db8e1fd23dcb1bdf377 (502.7 KB)
🔎 Searching bucket 10 33225590f6e59be23c7b19efb54e08c061b90bb939f0a4534eaed1ef87f14687 (1.7 MB)
🔎 Searching bucket 11 63af89b49f3ab43dde84daa2047a4f2da081a4c10e61434f491ac68cc1e5e18a (1.2 MB)
🔎 Searching bucket 12 2758104563674483875040222d4cea52764f826814049a7bd30525be9c46d6e3 (1.3 MB)
🔎 Searching bucket 13 999fc9861aeb6fffdd4dbd6d2c279b3ced16f86021551a657f4908a81e40fb23 (1.9 MB)
🔎 Searching bucket 14 d1389883fa330419b296ed24e55c9405c6161f543f791a267bf9bffbf84ef575 (4.7 MB)
🔎 Searching bucket 15 5a7583d1b8fe030ad03c4de6b8910839003be6d2e3912cb37496e3daf0d53892 (3.5 MB)
🔎 Searching bucket 16 0000d916c0cf7e3d21f1adc17dfb1c29b7bffe8aff0aa6e2915675f43326d61f (10.8 MB)
🔎 Searching bucket 17 0a512aa1cd406b12c1d5957ed9fa3c380571947a69c6dbdfe5a39662649683ea (20.6 MB)
🔎 Searching bucket 18 b5f49c714557ccf6686a15916538d96c9cec86ad7cb139d597f9b49dcc396153 (11.2 MB)
ℹ️ Adding wasm 2e9c9c399aadf4414b3e93c5fb855843b5bd9c16f755e6b712b76482e73ecc3e to search
ℹ️ Found 1 entries
ℹ️ Searching for 0 accounts, 0 contracts, 1 wasms
🔎 Searching bucket 0 3d0c5c771474d78b0c487fc318790b6c11778b4f0fe01b61e606be63a7bfdbb5 (1.0 KB)
🔎 Searching bucket 1 480f2887554305f8784cae7c7f61c6a44a8afa05a5de9b364b770486789cd75a (968 B)
🔎 Searching bucket 2 8d43c5813303a833212ddac9b0ecae09143e2c45cfd9c23d71baf612c6eba85a (1.5 KB)
🔎 Searching bucket 3 cf0741d8d0fd16e7db269e517d7b07c36a7ed008a2556f938d0f74f5569d5a3b (12.6 KB)
🔎 Searching bucket 4 a0ff94130d91984fd414eda7c9d8894412da54a8b63c302307bfb37d8a72df93 (8.1 KB)
🔎 Searching bucket 5 749c9da08b93334df184ce6ab138c2f104ddd6c922c2a57eabc3935df55fb94b (14.3 KB)
🔎 Searching bucket 6 df1eb96bfee2995c3f7a90d960a8c590cb651f4a3151603902abd6f90345d11d (14.7 KB)
🔎 Searching bucket 7 b9f507695fddbbde53ede71c0d591b3ac728ee236addef6044cafcf256fc7049 (41.3 KB)
🔎 Searching bucket 8 70dc0b5cba3338efcda81eb334210bc19c31941af24765ea9bcd246775c78ed2 (233.6 KB)
🔎 Searching bucket 9 ea3f2b433f40d11c7b0ccc17b134673e956b6ed5b1e02db8e1fd23dcb1bdf377 (502.7 KB)
🔎 Searching bucket 10 33225590f6e59be23c7b19efb54e08c061b90bb939f0a4534eaed1ef87f14687 (1.7 MB)
🔎 Searching bucket 11 63af89b49f3ab43dde84daa2047a4f2da081a4c10e61434f491ac68cc1e5e18a (1.2 MB)
🔎 Searching bucket 12 2758104563674483875040222d4cea52764f826814049a7bd30525be9c46d6e3 (1.3 MB)
🔎 Searching bucket 13 999fc9861aeb6fffdd4dbd6d2c279b3ced16f86021551a657f4908a81e40fb23 (1.9 MB)
🔎 Searching bucket 14 d1389883fa330419b296ed24e55c9405c6161f543f791a267bf9bffbf84ef575 (4.7 MB)
🔎 Searching bucket 15 5a7583d1b8fe030ad03c4de6b8910839003be6d2e3912cb37496e3daf0d53892 (3.5 MB)
🔎 Searching bucket 16 0000d916c0cf7e3d21f1adc17dfb1c29b7bffe8aff0aa6e2915675f43326d61f (10.8 MB)
🔎 Searching bucket 17 0a512aa1cd406b12c1d5957ed9fa3c380571947a69c6dbdfe5a39662649683ea (20.6 MB)
🔎 Searching bucket 18 b5f49c714557ccf6686a15916538d96c9cec86ad7cb139d597f9b49dcc396153 (11.2 MB)
ℹ️ Found 1 entries
💾 Saved 2 entries to "snapshot.json"
✅ Completed in 2s

$ cat snapshot.json | jq '.ledger_entries[0][0]'
{
  "contract_data": {
    "contract": "CBFPWZNGSIHLC4ZJ4SVPS4CXLH7YQJNCNRQN5EAH5AS7B44BKN4ELEQB",
    "key": "ledger_key_contract_instance",
    "durability": "persistent"
  }
}

Account name

Before:

$ stellar snapshot create --address alice --output json --out snapshot.json --network testnet
error: invalid value 'alice' for '--address <ADDRESS>': xdr value invalid

For more information, try '--help'.

After:

$ stellar keys address alice
GCFYGKMQVMRUUZAEICHTOEP7HIAYEVY3JEII33BYODEDDDGXU2BA5QD2

$ stellar snapshot create --address alice --output json --out snapshot.json --network testnet
🌎 Downloading history https://history.stellar.org/prd/core-testnet/core_testnet_001/.well-know
🌎 Downloaded history https://history.stellar.org/prd/core-testnet/core_testnet_001/.well-known/stellar-history.json
ℹ️ Ledger: 346751
ℹ️ Network Passphrase: Test SDF Network ; September 2015
ℹ️ Network id: cee0302d59844d32bdca915c8203dd44b33fbb7edc19051ea37abedf28ecd472
🌎 Downloaded bucket 0 d54468a052db9af3cac3a0b496525c27d2f76b6f249e00054e460f3ccbc803d1 (455 B)
🌎 Downloaded bucket 1 77e88b704c11d0609934622d115d9118892a1b12b3dcc8638219cfdec8fa52fc (559 B)
🌎 Downloaded bucket 2 42c8b1d8ff53ca6f42af68886e222dfbe9c9c661644be3d367a554c781837c65 (3.6 KB)
🌎 Downloaded bucket 3 aaff3da97fd8a48cf1c9f4424b6e12cfce3bb0763d36385ad4316cc60b424405 (812 B)
🌎 Downloaded bucket 4 1fd560c1351cdc022130810737daeb10aebdb90c10b00e84e4147515162589fa (4.3 KB)
🌎 Downloaded bucket 5 64e53a40871b1762f23ff65ec4d7fec8246ddcfeb4c29337c49a03290077d78e (3.8 KB)
🌎 Downloaded bucket 6 626f48303251d2f0e3a57dd69bc7d521ce443c80b705ba535004c2a2ddaea1d7 (12.5 KB)
ℹ️ Searching for 1 accounts, 0 contracts, 0 wasms
🔎 Searching bucket 0 d54468a052db9af3cac3a0b496525c27d2f76b6f249e00054e460f3ccbc803d1 (968 B)
🔎 Searching bucket 1 77e88b704c11d0609934622d115d9118892a1b12b3dcc8638219cfdec8fa52fc (1.2 KB)
🔎 Searching bucket 2 42c8b1d8ff53ca6f42af68886e222dfbe9c9c661644be3d367a554c781837c65 (7.2 KB)
🔎 Searching bucket 3 aaff3da97fd8a48cf1c9f4424b6e12cfce3bb0763d36385ad4316cc60b424405 (1.8 KB)
🔎 Searching bucket 4 1fd560c1351cdc022130810737daeb10aebdb90c10b00e84e4147515162589fa (12.8 KB)
🔎 Searching bucket 5 64e53a40871b1762f23ff65ec4d7fec8246ddcfeb4c29337c49a03290077d78e (11.0 KB)
🔎 Searching bucket 6 626f48303251d2f0e3a57dd69bc7d521ce443c80b705ba535004c2a2ddaea1d7 (39.2 KB)
🔎 Searching bucket 7 8d04e74d0ddee67afe8236dd60dba7c7994feeb66a447843509d930be49f513c (78.9 KB)
🔎 Searching bucket 8 e70040c3a2264a5e2255c62ed25a7862efb299366010d433e0354be0fbb158fd (31.7 KB)
🔎 Searching bucket 9 ea8843db095b712447d53049d2b2022d7903f2fb8137da153ff462b26d0ccb12 (150.1 KB)
🔎 Searching bucket 10 dfc0921f0bc516a0b98a0dbc4292d6a9e57e2e5d05702ed556cf1d37f6eede51 (713.7 KB)
🔎 Searching bucket 11 33225590f6e59be23c7b19efb54e08c061b90bb939f0a4534eaed1ef87f14687 (1.7 MB)
🔎 Searching bucket 12 46f9f7efb81a1eb707af7174caff70e60e37800ff7c6ee5110e364fd403024a2 (2.1 MB)
🔎 Searching bucket 13 999fc9861aeb6fffdd4dbd6d2c279b3ced16f86021551a657f4908a81e40fb23 (1.9 MB)
🔎 Searching bucket 14 d1389883fa330419b296ed24e55c9405c6161f543f791a267bf9bffbf84ef575 (4.7 MB)
🔎 Searching bucket 15 5a7583d1b8fe030ad03c4de6b8910839003be6d2e3912cb37496e3daf0d53892 (3.5 MB)
🔎 Searching bucket 16 0000d916c0cf7e3d21f1adc17dfb1c29b7bffe8aff0aa6e2915675f43326d61f (10.8 MB)
ℹ️ Found 1 entries
🔎 Searching bucket 17 0a512aa1cd406b12c1d5957ed9fa3c380571947a69c6dbdfe5a39662649683ea (20.6 MB)
🔎 Searching bucket 18 b5f49c714557ccf6686a15916538d96c9cec86ad7cb139d597f9b49dcc396153 (11.2 MB)
💾 Saved 1 entries to "snapshot.json"
✅ Completed in 2s

$ cat snapshot.json | jq '.ledger_entries[0][0]'
{
  "account": {
    "account_id": "GCFYGKMQVMRUUZAEICHTOEP7HIAYEVY3JEII33BYODEDDDGXU2BA5QD2"
  }
}

Why

So it supports contract aliasing.

Known limitations

N/A

@fnando fnando requested a review from leighmcculloch October 8, 2024 19:33
@willemneal
Copy link
Member

@fnando I suggest creating a new type for Contract Addresses. It would be useful in other commands. See this example of Address which can be a public key or an alias/seceret:

https://github.com/stellar/stellar-cli/blob/main/cmd/soroban-cli/src/config/address.rs

Then you can put the resolver logic there and make it easy to do something like self.contract.resolve(&self.locator)?.

@fnando
Copy link
Member Author

fnando commented Oct 8, 2024

@willemneal sounds good. I'll do that in a separate pr, because it'll be easier to grasp the refactoring.

@fnando fnando enabled auto-merge (squash) October 8, 2024 20:19
Copy link
Member

@willemneal willemneal left a comment

Choose a reason for hiding this comment

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

Suggestion to simplify and prepare for creating a ScAddress type we can work on in a future PR.

cmd/soroban-cli/src/commands/snapshot/create.rs Outdated Show resolved Hide resolved
cmd/soroban-cli/src/commands/snapshot/create.rs Outdated Show resolved Hide resolved
Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

Looks good. Suggestions by @willemneal also look good. One request to keep trust lines as two words.

Copy link
Member

@willemneal willemneal left a comment

Choose a reason for hiding this comment

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

LGTM

@fnando fnando disabled auto-merge October 9, 2024 18:56
@fnando fnando enabled auto-merge (squash) October 10, 2024 17:47
@fnando fnando merged commit 18fd1ff into main Oct 10, 2024
24 checks passed
@fnando fnando deleted the snapshot-create-strings branch October 10, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants