diff --git a/actions/burn_asset_ft.go b/actions/burn_asset_ft.go index f6ae399..d724783 100644 --- a/actions/burn_asset_ft.go +++ b/actions/burn_asset_ft.go @@ -92,9 +92,7 @@ func UnmarshalBurnAssetFT(p *codec.Packer) (chain.Action, error) { return &burn, p.Err() } -var ( - _ codec.Typed = (*BurnAssetFTResult)(nil) -) +var _ codec.Typed = (*BurnAssetFTResult)(nil) type BurnAssetFTResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/burn_asset_nft.go b/actions/burn_asset_nft.go index 162a4b3..36adf0c 100644 --- a/actions/burn_asset_nft.go +++ b/actions/burn_asset_nft.go @@ -108,9 +108,7 @@ func UnmarshalBurnAssetNFT(p *codec.Packer) (chain.Action, error) { return &burn, p.Err() } -var ( - _ codec.Typed = (*BurnAssetNFTResult)(nil) -) +var _ codec.Typed = (*BurnAssetNFTResult)(nil) type BurnAssetNFTResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/claim_delegation_stake_rewards.go b/actions/claim_delegation_stake_rewards.go index 82a8c28..9fb1b65 100644 --- a/actions/claim_delegation_stake_rewards.go +++ b/actions/claim_delegation_stake_rewards.go @@ -130,9 +130,7 @@ func UnmarshalClaimDelegationStakeRewards(p *codec.Packer) (chain.Action, error) return &claimRewards, p.Err() } -var ( - _ codec.Typed = (*ClaimDelegationStakeRewardsResult)(nil) -) +var _ codec.Typed = (*ClaimDelegationStakeRewardsResult)(nil) type ClaimDelegationStakeRewardsResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/claim_marketplace_payment.go b/actions/claim_marketplace_payment.go index 6523835..5e9e689 100644 --- a/actions/claim_marketplace_payment.go +++ b/actions/claim_marketplace_payment.go @@ -191,9 +191,7 @@ func UnmarshalClaimMarketplacePayment(p *codec.Packer) (chain.Action, error) { return &claimPaymentResult, p.Err() } -var ( - _ codec.Typed = (*ClaimMarketplacePaymentResult)(nil) -) +var _ codec.Typed = (*ClaimMarketplacePaymentResult)(nil) type ClaimMarketplacePaymentResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/claim_validator_stake_rewards.go b/actions/claim_validator_stake_rewards.go index ad6df58..c5f0a03 100644 --- a/actions/claim_validator_stake_rewards.go +++ b/actions/claim_validator_stake_rewards.go @@ -127,9 +127,7 @@ func UnmarshalClaimValidatorStakeRewards(p *codec.Packer) (chain.Action, error) return &claimRewards, p.Err() } -var ( - _ codec.Typed = (*ClaimValidatorStakeRewardsResult)(nil) -) +var _ codec.Typed = (*ClaimValidatorStakeRewardsResult)(nil) type ClaimValidatorStakeRewardsResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/complete_contribute_dataset.go b/actions/complete_contribute_dataset.go index 7a06382..f612a87 100644 --- a/actions/complete_contribute_dataset.go +++ b/actions/complete_contribute_dataset.go @@ -177,9 +177,7 @@ func UnmarshalCompleteContributeDataset(p *codec.Packer) (chain.Action, error) { return &complete, p.Err() } -var ( - _ codec.Typed = (*CompleteContributeDatasetResult)(nil) -) +var _ codec.Typed = (*CompleteContributeDatasetResult)(nil) type CompleteContributeDatasetResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/contract_deploy.go b/actions/contract_deploy.go index b9e6d78..d10d6da 100644 --- a/actions/contract_deploy.go +++ b/actions/contract_deploy.go @@ -88,9 +88,7 @@ func UnmarshalDeployContract(p *codec.Packer) (chain.Action, error) { return &deployContract, nil } -var ( - _ codec.Typed = (*ContractDeployResult)(nil) -) +var _ codec.Typed = (*ContractDeployResult)(nil) type ContractDeployResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/create_asset.go b/actions/create_asset.go index 2ebfddb..75de49d 100644 --- a/actions/create_asset.go +++ b/actions/create_asset.go @@ -194,9 +194,7 @@ func UnmarshalCreateAsset(p *codec.Packer) (chain.Action, error) { return &create, p.Err() } -var ( - _ codec.Typed = (*CreateAssetResult)(nil) -) +var _ codec.Typed = (*CreateAssetResult)(nil) type CreateAssetResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/create_dataset.go b/actions/create_dataset.go index 5c9c580..4d98eb7 100644 --- a/actions/create_dataset.go +++ b/actions/create_dataset.go @@ -163,9 +163,7 @@ func UnmarshalCreateDataset(p *codec.Packer) (chain.Action, error) { return &create, p.Err() } -var ( - _ codec.Typed = (*CreateDatasetResult)(nil) -) +var _ codec.Typed = (*CreateDatasetResult)(nil) type CreateDatasetResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/delegate_user_stake.go b/actions/delegate_user_stake.go index 2ad26b8..696b084 100644 --- a/actions/delegate_user_stake.go +++ b/actions/delegate_user_stake.go @@ -171,9 +171,7 @@ func UnmarshalDelegateUserStake(p *codec.Packer) (chain.Action, error) { return &stake, p.Err() } -var ( - _ codec.Typed = (*DelegateUserStakeResult)(nil) -) +var _ codec.Typed = (*DelegateUserStakeResult)(nil) type DelegateUserStakeResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/initiate_contribute_dataset.go b/actions/initiate_contribute_dataset.go index f50dd59..2b31b6a 100644 --- a/actions/initiate_contribute_dataset.go +++ b/actions/initiate_contribute_dataset.go @@ -149,9 +149,7 @@ func UnmarshalInitiateContributeDataset(p *codec.Packer) (chain.Action, error) { return &initiate, p.Err() } -var ( - _ codec.Typed = (*InitiateContributeDatasetResult)(nil) -) +var _ codec.Typed = (*InitiateContributeDatasetResult)(nil) type InitiateContributeDatasetResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/mint_asset_ft.go b/actions/mint_asset_ft.go index 9e711a1..391c2a6 100644 --- a/actions/mint_asset_ft.go +++ b/actions/mint_asset_ft.go @@ -108,9 +108,7 @@ func UnmarshalMintAssetFT(p *codec.Packer) (chain.Action, error) { return &mint, p.Err() } -var ( - _ codec.Typed = (*MintAssetFTResult)(nil) -) +var _ codec.Typed = (*MintAssetFTResult)(nil) type MintAssetFTResult struct { Actor string `serialize:"true" json:"actor"` @@ -122,6 +120,7 @@ type MintAssetFTResult struct { func (*MintAssetFTResult) GetTypeID() uint8 { return nconsts.MintAssetFTID } + func UnmarshalMintAssetFTResult(p *codec.Packer) (codec.Typed, error) { var result MintAssetFTResult result.Actor = p.UnpackString(true) diff --git a/actions/mint_asset_nft.go b/actions/mint_asset_nft.go index 5861cea..6eca7b0 100644 --- a/actions/mint_asset_nft.go +++ b/actions/mint_asset_nft.go @@ -126,9 +126,7 @@ func UnmarshalMintAssetNFT(p *codec.Packer) (chain.Action, error) { return &mint, p.Err() } -var ( - _ codec.Typed = (*MintAssetNFTResult)(nil) -) +var _ codec.Typed = (*MintAssetNFTResult)(nil) type MintAssetNFTResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/publish_dataset_marketplace.go b/actions/publish_dataset_marketplace.go index 883dccb..1b246f1 100644 --- a/actions/publish_dataset_marketplace.go +++ b/actions/publish_dataset_marketplace.go @@ -129,9 +129,7 @@ func UnmarshalPublishDatasetMarketplace(p *codec.Packer) (chain.Action, error) { return &publish, p.Err() } -var ( - _ codec.Typed = (*PublishDatasetMarketplaceResult)(nil) -) +var _ codec.Typed = (*PublishDatasetMarketplaceResult)(nil) type PublishDatasetMarketplaceResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/register_validator_stake.go b/actions/register_validator_stake.go index cea3560..7350306 100644 --- a/actions/register_validator_stake.go +++ b/actions/register_validator_stake.go @@ -268,9 +268,7 @@ func UnmarshalValidatorStakeInfo(p *codec.Packer) (*ValidatorStakeInfo, error) { return &result, p.Err() } -var ( - _ codec.Typed = (*RegisterValidatorStakeResult)(nil) -) +var _ codec.Typed = (*RegisterValidatorStakeResult)(nil) type RegisterValidatorStakeResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/subscribe_dataset_marketplace.go b/actions/subscribe_dataset_marketplace.go index f593ca4..59b9d19 100644 --- a/actions/subscribe_dataset_marketplace.go +++ b/actions/subscribe_dataset_marketplace.go @@ -221,9 +221,7 @@ func UnmarshalSubscribeDatasetMarketplace(p *codec.Packer) (chain.Action, error) return &subscribe, p.Err() } -var ( - _ codec.Typed = (*SubscribeDatasetMarketplaceResult)(nil) -) +var _ codec.Typed = (*SubscribeDatasetMarketplaceResult)(nil) type SubscribeDatasetMarketplaceResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/transfer.go b/actions/transfer.go index fd836ae..5a3fde3 100644 --- a/actions/transfer.go +++ b/actions/transfer.go @@ -124,9 +124,7 @@ func UnmarshalTransfer(p *codec.Packer) (chain.Action, error) { return &transfer, p.Err() } -var ( - _ codec.Typed = (*TransferResult)(nil) -) +var _ codec.Typed = (*TransferResult)(nil) type TransferResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/undelegate_user_stake.go b/actions/undelegate_user_stake.go index aec3da6..d55d40b 100644 --- a/actions/undelegate_user_stake.go +++ b/actions/undelegate_user_stake.go @@ -129,9 +129,7 @@ func UnmarshalUndelegateUserStake(p *codec.Packer) (chain.Action, error) { return &unstake, p.Err() } -var ( - _ codec.Typed = (*UndelegateUserStakeResult)(nil) -) +var _ codec.Typed = (*UndelegateUserStakeResult)(nil) type UndelegateUserStakeResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/undelegate_user_stake_test.go b/actions/undelegate_user_stake_test.go index eab569d..e149a47 100644 --- a/actions/undelegate_user_stake_test.go +++ b/actions/undelegate_user_stake_test.go @@ -86,8 +86,8 @@ func TestUndelegateUserStakeActionSuccess(t *testing.T) { require.False(t, exists) }, ExpectedOutputs: &UndelegateUserStakeResult{ - Actor: actor.String(), - Receiver: actor.String(), + Actor: actor.String(), + Receiver: actor.String(), StakeStartBlock: 25, StakeEndBlock: 50, UnstakedAmount: 1000, diff --git a/actions/update_asset.go b/actions/update_asset.go index 66424c4..ca7b92e 100644 --- a/actions/update_asset.go +++ b/actions/update_asset.go @@ -209,9 +209,7 @@ func UnmarshalUpdateAsset(p *codec.Packer) (chain.Action, error) { return &create, p.Err() } -var ( - _ codec.Typed = (*UpdateAssetResult)(nil) -) +var _ codec.Typed = (*UpdateAssetResult)(nil) type UpdateAssetResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/update_dataset.go b/actions/update_dataset.go index a6dccd1..75bbe0a 100644 --- a/actions/update_dataset.go +++ b/actions/update_dataset.go @@ -171,9 +171,7 @@ func UnmarshalUpdateDataset(p *codec.Packer) (chain.Action, error) { return &update, p.Err() } -var ( - _ codec.Typed = (*UpdateDatasetResult)(nil) -) +var _ codec.Typed = (*UpdateDatasetResult)(nil) type UpdateDatasetResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/actions/withdraw_validator_stake.go b/actions/withdraw_validator_stake.go index c6aea6a..c34687a 100644 --- a/actions/withdraw_validator_stake.go +++ b/actions/withdraw_validator_stake.go @@ -140,9 +140,7 @@ func UnmarshalWithdrawValidatorStake(p *codec.Packer) (chain.Action, error) { return &unstake, p.Err() } -var ( - _ codec.Typed = (*WithdrawValidatorStakeResult)(nil) -) +var _ codec.Typed = (*WithdrawValidatorStakeResult)(nil) type WithdrawValidatorStakeResult struct { Actor string `serialize:"true" json:"actor"` diff --git a/cmd/nuklai-cli/cmd/utils.go b/cmd/nuklai-cli/cmd/utils.go index 8c9faf4..d7cca19 100644 --- a/cmd/nuklai-cli/cmd/utils.go +++ b/cmd/nuklai-cli/cmd/utils.go @@ -79,17 +79,17 @@ func processResult(result *chain.Result) error { // Automatically handle all types by reflecting and marshaling to JSON reflectValue := reflect.ValueOf(r) - if reflectValue.IsValid() && !reflectValue.IsZero() { - // Marshal the result to JSON for a generic and readable output - outputJSON, err := json.MarshalIndent(r, "", " ") - if err != nil { - return fmt.Errorf("failed to marshal result: %w", err) - } - - utils.Outf("{{green}}output:{{/}} %s\n", string(outputJSON)) - } else { + if !reflectValue.IsValid() || reflectValue.IsZero() { return errors.New("result is invalid or nil") } + + // Marshal the result to JSON for a generic and readable output + outputJSON, err := json.MarshalIndent(r, "", " ") + if err != nil { + return fmt.Errorf("failed to marshal result: %w", err) + } + + utils.Outf("{{green}}output:{{/}} %s\n", string(outputJSON)) } return nil }