Skip to content

Commit dc06e8f

Browse files
committed
Simplified the code to reduce unnecessary nesting
1 parent 6240236 commit dc06e8f

23 files changed

+33
-74
lines changed

actions/burn_asset_ft.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ func UnmarshalBurnAssetFT(p *codec.Packer) (chain.Action, error) {
9292
return &burn, p.Err()
9393
}
9494

95-
var (
96-
_ codec.Typed = (*BurnAssetFTResult)(nil)
97-
)
95+
var _ codec.Typed = (*BurnAssetFTResult)(nil)
9896

9997
type BurnAssetFTResult struct {
10098
Actor string `serialize:"true" json:"actor"`

actions/burn_asset_nft.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ func UnmarshalBurnAssetNFT(p *codec.Packer) (chain.Action, error) {
108108
return &burn, p.Err()
109109
}
110110

111-
var (
112-
_ codec.Typed = (*BurnAssetNFTResult)(nil)
113-
)
111+
var _ codec.Typed = (*BurnAssetNFTResult)(nil)
114112

115113
type BurnAssetNFTResult struct {
116114
Actor string `serialize:"true" json:"actor"`

actions/claim_delegation_stake_rewards.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ func UnmarshalClaimDelegationStakeRewards(p *codec.Packer) (chain.Action, error)
130130
return &claimRewards, p.Err()
131131
}
132132

133-
var (
134-
_ codec.Typed = (*ClaimDelegationStakeRewardsResult)(nil)
135-
)
133+
var _ codec.Typed = (*ClaimDelegationStakeRewardsResult)(nil)
136134

137135
type ClaimDelegationStakeRewardsResult struct {
138136
Actor string `serialize:"true" json:"actor"`

actions/claim_marketplace_payment.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ func UnmarshalClaimMarketplacePayment(p *codec.Packer) (chain.Action, error) {
191191
return &claimPaymentResult, p.Err()
192192
}
193193

194-
var (
195-
_ codec.Typed = (*ClaimMarketplacePaymentResult)(nil)
196-
)
194+
var _ codec.Typed = (*ClaimMarketplacePaymentResult)(nil)
197195

198196
type ClaimMarketplacePaymentResult struct {
199197
Actor string `serialize:"true" json:"actor"`

actions/claim_validator_stake_rewards.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ func UnmarshalClaimValidatorStakeRewards(p *codec.Packer) (chain.Action, error)
127127
return &claimRewards, p.Err()
128128
}
129129

130-
var (
131-
_ codec.Typed = (*ClaimValidatorStakeRewardsResult)(nil)
132-
)
130+
var _ codec.Typed = (*ClaimValidatorStakeRewardsResult)(nil)
133131

134132
type ClaimValidatorStakeRewardsResult struct {
135133
Actor string `serialize:"true" json:"actor"`

actions/complete_contribute_dataset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ func UnmarshalCompleteContributeDataset(p *codec.Packer) (chain.Action, error) {
177177
return &complete, p.Err()
178178
}
179179

180-
var (
181-
_ codec.Typed = (*CompleteContributeDatasetResult)(nil)
182-
)
180+
var _ codec.Typed = (*CompleteContributeDatasetResult)(nil)
183181

184182
type CompleteContributeDatasetResult struct {
185183
Actor string `serialize:"true" json:"actor"`

actions/contract_deploy.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ func UnmarshalDeployContract(p *codec.Packer) (chain.Action, error) {
8888
return &deployContract, nil
8989
}
9090

91-
var (
92-
_ codec.Typed = (*ContractDeployResult)(nil)
93-
)
91+
var _ codec.Typed = (*ContractDeployResult)(nil)
9492

9593
type ContractDeployResult struct {
9694
Actor string `serialize:"true" json:"actor"`

actions/create_asset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ func UnmarshalCreateAsset(p *codec.Packer) (chain.Action, error) {
194194
return &create, p.Err()
195195
}
196196

197-
var (
198-
_ codec.Typed = (*CreateAssetResult)(nil)
199-
)
197+
var _ codec.Typed = (*CreateAssetResult)(nil)
200198

201199
type CreateAssetResult struct {
202200
Actor string `serialize:"true" json:"actor"`

actions/create_dataset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ func UnmarshalCreateDataset(p *codec.Packer) (chain.Action, error) {
163163
return &create, p.Err()
164164
}
165165

166-
var (
167-
_ codec.Typed = (*CreateDatasetResult)(nil)
168-
)
166+
var _ codec.Typed = (*CreateDatasetResult)(nil)
169167

170168
type CreateDatasetResult struct {
171169
Actor string `serialize:"true" json:"actor"`

actions/delegate_user_stake.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ func UnmarshalDelegateUserStake(p *codec.Packer) (chain.Action, error) {
171171
return &stake, p.Err()
172172
}
173173

174-
var (
175-
_ codec.Typed = (*DelegateUserStakeResult)(nil)
176-
)
174+
var _ codec.Typed = (*DelegateUserStakeResult)(nil)
177175

178176
type DelegateUserStakeResult struct {
179177
Actor string `serialize:"true" json:"actor"`

actions/initiate_contribute_dataset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ func UnmarshalInitiateContributeDataset(p *codec.Packer) (chain.Action, error) {
149149
return &initiate, p.Err()
150150
}
151151

152-
var (
153-
_ codec.Typed = (*InitiateContributeDatasetResult)(nil)
154-
)
152+
var _ codec.Typed = (*InitiateContributeDatasetResult)(nil)
155153

156154
type InitiateContributeDatasetResult struct {
157155
Actor string `serialize:"true" json:"actor"`

actions/mint_asset_ft.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ func UnmarshalMintAssetFT(p *codec.Packer) (chain.Action, error) {
108108
return &mint, p.Err()
109109
}
110110

111-
var (
112-
_ codec.Typed = (*MintAssetFTResult)(nil)
113-
)
111+
var _ codec.Typed = (*MintAssetFTResult)(nil)
114112

115113
type MintAssetFTResult struct {
116114
Actor string `serialize:"true" json:"actor"`
@@ -122,6 +120,7 @@ type MintAssetFTResult struct {
122120
func (*MintAssetFTResult) GetTypeID() uint8 {
123121
return nconsts.MintAssetFTID
124122
}
123+
125124
func UnmarshalMintAssetFTResult(p *codec.Packer) (codec.Typed, error) {
126125
var result MintAssetFTResult
127126
result.Actor = p.UnpackString(true)

actions/mint_asset_nft.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ func UnmarshalMintAssetNFT(p *codec.Packer) (chain.Action, error) {
126126
return &mint, p.Err()
127127
}
128128

129-
var (
130-
_ codec.Typed = (*MintAssetNFTResult)(nil)
131-
)
129+
var _ codec.Typed = (*MintAssetNFTResult)(nil)
132130

133131
type MintAssetNFTResult struct {
134132
Actor string `serialize:"true" json:"actor"`

actions/publish_dataset_marketplace.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ func UnmarshalPublishDatasetMarketplace(p *codec.Packer) (chain.Action, error) {
129129
return &publish, p.Err()
130130
}
131131

132-
var (
133-
_ codec.Typed = (*PublishDatasetMarketplaceResult)(nil)
134-
)
132+
var _ codec.Typed = (*PublishDatasetMarketplaceResult)(nil)
135133

136134
type PublishDatasetMarketplaceResult struct {
137135
Actor string `serialize:"true" json:"actor"`

actions/register_validator_stake.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ func UnmarshalValidatorStakeInfo(p *codec.Packer) (*ValidatorStakeInfo, error) {
268268
return &result, p.Err()
269269
}
270270

271-
var (
272-
_ codec.Typed = (*RegisterValidatorStakeResult)(nil)
273-
)
271+
var _ codec.Typed = (*RegisterValidatorStakeResult)(nil)
274272

275273
type RegisterValidatorStakeResult struct {
276274
Actor string `serialize:"true" json:"actor"`

actions/subscribe_dataset_marketplace.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ func UnmarshalSubscribeDatasetMarketplace(p *codec.Packer) (chain.Action, error)
221221
return &subscribe, p.Err()
222222
}
223223

224-
var (
225-
_ codec.Typed = (*SubscribeDatasetMarketplaceResult)(nil)
226-
)
224+
var _ codec.Typed = (*SubscribeDatasetMarketplaceResult)(nil)
227225

228226
type SubscribeDatasetMarketplaceResult struct {
229227
Actor string `serialize:"true" json:"actor"`

actions/transfer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ func UnmarshalTransfer(p *codec.Packer) (chain.Action, error) {
124124
return &transfer, p.Err()
125125
}
126126

127-
var (
128-
_ codec.Typed = (*TransferResult)(nil)
129-
)
127+
var _ codec.Typed = (*TransferResult)(nil)
130128

131129
type TransferResult struct {
132130
Actor string `serialize:"true" json:"actor"`

actions/undelegate_user_stake.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ func UnmarshalUndelegateUserStake(p *codec.Packer) (chain.Action, error) {
129129
return &unstake, p.Err()
130130
}
131131

132-
var (
133-
_ codec.Typed = (*UndelegateUserStakeResult)(nil)
134-
)
132+
var _ codec.Typed = (*UndelegateUserStakeResult)(nil)
135133

136134
type UndelegateUserStakeResult struct {
137135
Actor string `serialize:"true" json:"actor"`

actions/undelegate_user_stake_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func TestUndelegateUserStakeActionSuccess(t *testing.T) {
8686
require.False(t, exists)
8787
},
8888
ExpectedOutputs: &UndelegateUserStakeResult{
89-
Actor: actor.String(),
90-
Receiver: actor.String(),
89+
Actor: actor.String(),
90+
Receiver: actor.String(),
9191
StakeStartBlock: 25,
9292
StakeEndBlock: 50,
9393
UnstakedAmount: 1000,

actions/update_asset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ func UnmarshalUpdateAsset(p *codec.Packer) (chain.Action, error) {
209209
return &create, p.Err()
210210
}
211211

212-
var (
213-
_ codec.Typed = (*UpdateAssetResult)(nil)
214-
)
212+
var _ codec.Typed = (*UpdateAssetResult)(nil)
215213

216214
type UpdateAssetResult struct {
217215
Actor string `serialize:"true" json:"actor"`

actions/update_dataset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ func UnmarshalUpdateDataset(p *codec.Packer) (chain.Action, error) {
171171
return &update, p.Err()
172172
}
173173

174-
var (
175-
_ codec.Typed = (*UpdateDatasetResult)(nil)
176-
)
174+
var _ codec.Typed = (*UpdateDatasetResult)(nil)
177175

178176
type UpdateDatasetResult struct {
179177
Actor string `serialize:"true" json:"actor"`

actions/withdraw_validator_stake.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ func UnmarshalWithdrawValidatorStake(p *codec.Packer) (chain.Action, error) {
140140
return &unstake, p.Err()
141141
}
142142

143-
var (
144-
_ codec.Typed = (*WithdrawValidatorStakeResult)(nil)
145-
)
143+
var _ codec.Typed = (*WithdrawValidatorStakeResult)(nil)
146144

147145
type WithdrawValidatorStakeResult struct {
148146
Actor string `serialize:"true" json:"actor"`

cmd/nuklai-cli/cmd/utils.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ func processResult(result *chain.Result) error {
7979

8080
// Automatically handle all types by reflecting and marshaling to JSON
8181
reflectValue := reflect.ValueOf(r)
82-
if reflectValue.IsValid() && !reflectValue.IsZero() {
83-
// Marshal the result to JSON for a generic and readable output
84-
outputJSON, err := json.MarshalIndent(r, "", " ")
85-
if err != nil {
86-
return fmt.Errorf("failed to marshal result: %w", err)
87-
}
88-
89-
utils.Outf("{{green}}output:{{/}} %s\n", string(outputJSON))
90-
} else {
82+
if !reflectValue.IsValid() || reflectValue.IsZero() {
9183
return errors.New("result is invalid or nil")
9284
}
85+
86+
// Marshal the result to JSON for a generic and readable output
87+
outputJSON, err := json.MarshalIndent(r, "", " ")
88+
if err != nil {
89+
return fmt.Errorf("failed to marshal result: %w", err)
90+
}
91+
92+
utils.Outf("{{green}}output:{{/}} %s\n", string(outputJSON))
9393
}
9494
return nil
9595
}

0 commit comments

Comments
 (0)