diff --git a/actions.go b/actions.go index 404e8b9..0cd1d82 100644 --- a/actions.go +++ b/actions.go @@ -340,3 +340,61 @@ func actionValidateAddress(ctx context.Context, opts core.Options) core.Result { "valid": valid, "type": addrType, }, OK: true} } + +// RegisterAssetActions registers HF5 confidential asset actions. +// +// blockchain.RegisterAssetActions(c) +func RegisterAssetActions(c *core.Core) { + c.Action("blockchain.asset.info", actionAssetInfo) + c.Action("blockchain.asset.list", actionAssetList) + c.Action("blockchain.asset.deploy", actionAssetDeploy) +} + +func actionAssetInfo(ctx context.Context, opts core.Options) core.Result { + assetID := opts.String("asset_id") + if assetID == "" || assetID == "LTHN" { + return core.Result{Value: map[string]interface{}{ + "ticker": "LTHN", "name": "Lethean", "decimals": 12, + "native": true, + }, OK: true} + } + return core.Result{OK: false} +} + +func actionAssetList(ctx context.Context, opts core.Options) core.Result { + return core.Result{Value: []map[string]interface{}{ + {"ticker": "LTHN", "name": "Lethean", "native": true}, + }, OK: true} +} + +func actionAssetDeploy(ctx context.Context, opts core.Options) core.Result { + ticker := opts.String("ticker") + name := opts.String("name") + if ticker == "" || name == "" { + return core.Result{OK: false} + } + return core.Result{Value: map[string]interface{}{ + "ticker": ticker, "name": name, "status": "ready_for_hf5", + }, OK: true} +} + +// RegisterForgeActions registers forge integration actions. +// +// blockchain.RegisterForgeActions(c) +func RegisterForgeActions(c *core.Core) { + c.Action("blockchain.forge.release", forgePublishRelease) + c.Action("blockchain.forge.issue", forgeCreateIssue) + c.Action("blockchain.forge.build", forgeDispatchBuild) + c.Action("blockchain.forge.event", forgeChainEvent) +} + +// RegisterAllActions registers every blockchain action with Core. +// +// blockchain.RegisterAllActions(c, chain) +func RegisterAllActions(c *core.Core, ch *chain.Chain) { + RegisterActions(c, ch) + RegisterWalletActions(c) + RegisterCryptoActions(c) + RegisterAssetActions(c) + RegisterForgeActions(c) +} diff --git a/actions_test.go b/actions_test.go index 78d552b..dcb1da1 100644 --- a/actions_test.go +++ b/actions_test.go @@ -71,3 +71,31 @@ func TestAction_ValidateAddress_Good(t *testing.T) { t.Errorf("type: got %v, want standard", m["type"]) } } + +func TestAction_AssetInfo_Good(t *testing.T) { + result := actionAssetInfo(context.Background(), core.NewOptions(core.Option{Key: "asset_id", Value: "LTHN"})) + if !result.OK { t.Fatal("failed") } + m := result.Value.(map[string]interface{}) + if m["ticker"] != "LTHN" { t.Error("wrong ticker") } +} + +func TestAction_AssetList_Good(t *testing.T) { + result := actionAssetList(context.Background(), core.Options{}) + if !result.OK { t.Fatal("failed") } +} + +func TestAction_AssetDeploy_Bad(t *testing.T) { + result := actionAssetDeploy(context.Background(), core.Options{}) + if result.OK { t.Error("should fail without ticker") } +} + +func TestAction_RegisterAll_Good(t *testing.T) { + c := core.New() + RegisterAllActions(c, nil) + // Verify actions exist + if !c.Action("blockchain.chain.height").Exists() { t.Error("chain.height not registered") } + if !c.Action("blockchain.wallet.create").Exists() { t.Error("wallet.create not registered") } + if !c.Action("blockchain.crypto.hash").Exists() { t.Error("crypto.hash not registered") } + if !c.Action("blockchain.asset.info").Exists() { t.Error("asset.info not registered") } + if !c.Action("blockchain.forge.release").Exists() { t.Error("forge.release not registered") } +}