feat: add 3 wallet Core actions (create, address, seed)
blockchain.wallet.create — generate wallet, return address + seed blockchain.wallet.address — derive all address types from seed blockchain.wallet.seed — generate fresh mnemonic seed 19 total Core actions. All pure core.Options → core.Result. No banned imports in action handlers. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
24fee95962
commit
87e771d228
1 changed files with 50 additions and 0 deletions
50
actions.go
50
actions.go
|
|
@ -9,6 +9,7 @@ import (
|
|||
"dappco.re/go/core"
|
||||
|
||||
"dappco.re/go/core/blockchain/chain"
|
||||
"dappco.re/go/core/blockchain/wallet"
|
||||
)
|
||||
|
||||
// RegisterActions registers all blockchain actions with a Core instance.
|
||||
|
|
@ -238,3 +239,52 @@ func parseActionComment(comment string) map[string]string {
|
|||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
// RegisterWalletActions registers wallet-related Core actions.
|
||||
//
|
||||
// blockchain.RegisterWalletActions(c)
|
||||
func RegisterWalletActions(c *core.Core) {
|
||||
c.Action("blockchain.wallet.create", actionWalletCreate)
|
||||
c.Action("blockchain.wallet.address", actionWalletAddress)
|
||||
c.Action("blockchain.wallet.seed", actionWalletSeed)
|
||||
}
|
||||
|
||||
func actionWalletCreate(ctx context.Context, opts core.Options) core.Result {
|
||||
account, err := wallet.GenerateAccount()
|
||||
if err != nil {
|
||||
return core.Result{OK: false}
|
||||
}
|
||||
addr := account.Address()
|
||||
seed, _ := account.ToSeed()
|
||||
return core.Result{Value: map[string]interface{}{
|
||||
"address": addr.Encode(StandardPrefix),
|
||||
"seed": seed,
|
||||
}, OK: true}
|
||||
}
|
||||
|
||||
func actionWalletAddress(ctx context.Context, opts core.Options) core.Result {
|
||||
seed := opts.String("seed")
|
||||
if seed == "" {
|
||||
return core.Result{OK: false}
|
||||
}
|
||||
account, err := wallet.RestoreFromSeed(seed)
|
||||
if err != nil {
|
||||
return core.Result{OK: false}
|
||||
}
|
||||
addr := account.Address()
|
||||
return core.Result{Value: map[string]interface{}{
|
||||
"standard": addr.Encode(StandardPrefix),
|
||||
"integrated": addr.Encode(IntegratedPrefix),
|
||||
"auditable": addr.Encode(AuditablePrefix),
|
||||
}, OK: true}
|
||||
}
|
||||
|
||||
func actionWalletSeed(ctx context.Context, opts core.Options) core.Result {
|
||||
// Generate a fresh seed (no wallet file needed)
|
||||
account, err := wallet.GenerateAccount()
|
||||
if err != nil {
|
||||
return core.Result{OK: false}
|
||||
}
|
||||
seed, _ := account.ToSeed()
|
||||
return core.Result{Value: seed, OK: true}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue