Skip to content

Commit

Permalink
Simplified the code to reduce unnecessary nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
kpachhai committed Dec 13, 2024
1 parent 6240236 commit dc06e8f
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 74 deletions.
4 changes: 1 addition & 3 deletions actions/burn_asset_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/burn_asset_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/claim_delegation_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/claim_marketplace_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/claim_validator_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/complete_contribute_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/contract_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/create_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/create_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/delegate_user_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/initiate_contribute_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 2 additions & 3 deletions actions/mint_asset_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions actions/mint_asset_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/publish_dataset_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/register_validator_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/subscribe_dataset_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/undelegate_user_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions actions/undelegate_user_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions actions/update_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/update_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions actions/withdraw_validator_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 9 additions & 9 deletions cmd/nuklai-cli/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dc06e8f

Please sign in to comment.