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 with ARK Sdk #224

Closed
wants to merge 13 commits into from
Closed

CLI with ARK Sdk #224

wants to merge 13 commits into from

Conversation

sekulicd
Copy link
Collaborator

@sekulicd sekulicd commented Jul 31, 2024

This updates CLI so that it uses arksdk.
Note that this depends on arksdk covenantless update, once arksdk is updated changes should be simple and applicable in here

This closes #218

@tiero @altafan @louisinger please review.

@tiero tiero marked this pull request as draft August 12, 2024 22:10
client/main.go Outdated
return printJSON(cfg)
}

func onboard(ctx *cli.Context) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be dropped once the pr is synced with master

})
}

func redeem(ctx *cli.Context) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if --force flag is set we must call arkSdkClient.UnilateralRedeem

client/main.go Outdated
Comment on lines 405 to 413
offchainAddr, onchainAddr, err := arkSdkClient.Receive(cntx)
if err != nil {
return err
}

return printJSON(map[string]interface{}{
"offchain_address": offchainAddr,
"onchain_address": onchainAddr,
})
Copy link
Collaborator

@altafan altafan Sep 10, 2024

Choose a reason for hiding this comment

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

Receive now returns the boarding address as onchain address:

Suggested change
offchainAddr, onchainAddr, err := arkSdkClient.Receive(cntx)
if err != nil {
return err
}
return printJSON(map[string]interface{}{
"offchain_address": offchainAddr,
"onchain_address": onchainAddr,
})
offchainAddr, boardingAddr, err := arkSdkClient.Receive(cntx)
if err != nil {
return err
}
return printJSON(map[string]interface{}{
"offchain_address": offchainAddr,
"boarding_address": boardingAddr,
})

@sekulicd sekulicd changed the title [WIP] CLI with ARK Sdk CLI with ARK Sdk Sep 11, 2024
@sekulicd sekulicd marked this pull request as ready for review September 12, 2024 08:38

path = strings.Replace(path, "~", homeDir, 1)
func decrypt(encrypted, password []byte) ([]byte, error) {
Copy link
Collaborator

@louisinger louisinger Sep 12, 2024

Choose a reason for hiding this comment

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

decrypt and encrypt are also implemented in the SDK package. Also they are used only to print the private key. Should we consider exporting the functions or maybe implement dumpPrivateKey in sdk ? cc @altafan @sekulicd

Copy link
Collaborator

@louisinger louisinger left a comment

Choose a reason for hiding this comment

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

Integration tests are not running in CI ? Is it expected ?

@sekulicd
Copy link
Collaborator Author

Integration tests are not running in CI ? Is it expected ?

Looks like they are triggered only if there are changes in /server which is wrong.

@@ -278,6 +280,13 @@ func receive(ctx *cli.Context) error {
}

func claim(ctx *cli.Context) error {
if err := arkSdkClient.Unlock(
Copy link
Member

Choose a reason for hiding this comment

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

wouldnt be more correct to check is IsUnlocked before trying to unlock an already unlocked SDK? to avoid extra roundtrip

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only way, AFAIK, that SDK loads primary key from memory, in the example itself similar flow is used.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but that wont help, when u init arksdk, pk is not loaded by default, and only place where pk is set is in Unlock method.
Calling IsLocked is meaningless in this case.

@@ -59,6 +59,7 @@ func main() {
return fmt.Errorf("error initializing ark sdk client: %v", err)
}
arkSdkClient = sdk

Copy link
Member

Choose a reason for hiding this comment

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

Are we sure in using a global variable here? Wouldnt be better to have it inside the context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dont see an issue with this, its one file, all function calls, purpose is just to avoid code repetition by setting up client in each func, so basically before each cmd call setup arksdk client and set global var to func.

Comment on lines +24 to +25
liquidRegTestUrl = getEnv("LIQUID_REGTEST_URL", "http://localhost:3001")
bitcoinRegTestUrl = getEnv("BITCOIN_REGTEST_URL", "http://localhost:3000")
Copy link
Member

@tiero tiero Sep 12, 2024

Choose a reason for hiding this comment

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

shouldn't we use here viper/urfave directly? Usually ENV are automatically ARK prefixed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

wanted to use quicker solution without 3rd party pkg's since this is only relevant for regtest.

Copy link
Member

@tiero tiero Sep 12, 2024

Choose a reason for hiding this comment

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

You can use EnvVars of cli when creating flags, so you have both a flag and an env var https://github.com/sekulicd/ark/blob/52b21c5e687111250b365e89438503e2327ce107/client/main.go#L79

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, but var supportedNetworks is inside sdk, imo this is simplest way to inject diff values for regtest without touching existing arksdk interface, otherwise we would need to pass network and this is not good since network comes from ASP via GetInfo. Instead of passing it via CLI env var i decided to pass it throuugh regtest dockerfile's.

Copy link
Member

@tiero tiero Sep 12, 2024

Choose a reason for hiding this comment

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

Also..we used to have an --explorer flag!!

Look at the current doc https://arkdev.info/docs/quick-start/client/#setting-up-alice-and-bobs-clients

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not relevant after sdk introduction, as there is no way to pass explorer url when creating instance, as said now explorer is created based on net retreived from ASP with GetInfo RPC.

Copy link
Member

@tiero tiero Sep 12, 2024

Choose a reason for hiding this comment

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

This is for sure wrong on the SDK side then. Let's fix it!

The explorer URL SHOULD NOT be mandated by the connected ASP, as is used to fetch blockchain data which is an open protocol. (I guess to check onchain balance? Compute timestamps from blocks?).

It's very likely user of the SDK wants to use their explorer, instead being us forcing them with some well-known explorer URLs.

@sekulicd sekulicd closed this Sep 13, 2024
@sekulicd sekulicd mentioned this pull request Sep 13, 2024
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] Use sdk
4 participants