diff --git a/actions/burn_asset_ft.go b/actions/burn_asset_ft.go index 09725ce..fad8c71 100644 --- a/actions/burn_asset_ft.go +++ b/actions/burn_asset_ft.go @@ -70,8 +70,9 @@ func (b *BurnAssetFT) Execute( } return &BurnAssetFTResult{ - OldBalance: newBalance + b.Value, - NewBalance: newBalance, + CommonResult: FillCommonResult(actor.String(), ""), + OldBalance: newBalance + b.Value, + NewBalance: newBalance, }, nil } @@ -97,6 +98,7 @@ var ( ) type BurnAssetFTResult struct { + CommonResult OldBalance uint64 `serialize:"true" json:"old_balance"` NewBalance uint64 `serialize:"true" json:"new_balance"` } diff --git a/actions/burn_asset_nft.go b/actions/burn_asset_nft.go index 4d09c43..4183b8d 100644 --- a/actions/burn_asset_nft.go +++ b/actions/burn_asset_nft.go @@ -86,8 +86,9 @@ func (b *BurnAssetNFT) Execute( } return &BurnAssetNFTResult{ - OldBalance: newBalance + 1, - NewBalance: newBalance, + CommonResult: FillCommonResult(actor.String(), ""), + OldBalance: newBalance + 1, + NewBalance: newBalance, }, nil } @@ -113,6 +114,7 @@ var ( ) type BurnAssetNFTResult struct { + CommonResult OldBalance uint64 `serialize:"true" json:"old_balance"` NewBalance uint64 `serialize:"true" json:"new_balance"` } diff --git a/actions/claim_delegation_stake_rewards.go b/actions/claim_delegation_stake_rewards.go index d582be7..4ee9955 100644 --- a/actions/claim_delegation_stake_rewards.go +++ b/actions/claim_delegation_stake_rewards.go @@ -89,6 +89,7 @@ func (c *ClaimDelegationStakeRewards) Execute( } return &ClaimDelegationStakeRewardsResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), StakeStartBlock: stakeStartBlock, StakeEndBlock: stakeEndBlock, StakedAmount: stakedAmount, @@ -135,6 +136,7 @@ var ( ) type ClaimDelegationStakeRewardsResult struct { + CommonResult StakeStartBlock uint64 `serialize:"true" json:"stake_start_block"` StakeEndBlock uint64 `serialize:"true" json:"stake_end_block"` StakedAmount uint64 `serialize:"true" json:"staked_amount"` diff --git a/actions/claim_marketplace_payment.go b/actions/claim_marketplace_payment.go index 9648218..5336baf 100644 --- a/actions/claim_marketplace_payment.go +++ b/actions/claim_marketplace_payment.go @@ -166,6 +166,7 @@ func (c *ClaimMarketplacePayment) Execute( } return &ClaimMarketplacePaymentResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), LastClaimedBlock: lastClaimedBlock, PaymentClaimed: paymentClaimed, PaymentRemaining: paymentRemaining, @@ -196,6 +197,7 @@ var ( ) type ClaimMarketplacePaymentResult struct { + CommonResult LastClaimedBlock uint64 `serialize:"true" json:"last_claimed_block"` PaymentClaimed uint64 `serialize:"true" json:"payment_claimed"` PaymentRemaining uint64 `serialize:"true" json:"payment_remaining"` diff --git a/actions/claim_validator_stake_rewards.go b/actions/claim_validator_stake_rewards.go index a3602fd..f7776fc 100644 --- a/actions/claim_validator_stake_rewards.go +++ b/actions/claim_validator_stake_rewards.go @@ -85,6 +85,7 @@ func (c *ClaimValidatorStakeRewards) Execute( } return &ClaimValidatorStakeRewardsResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), StakeStartBlock: stakeStartBlock, StakeEndBlock: stakeEndBlock, StakedAmount: stakeAmount, @@ -132,6 +133,7 @@ var ( ) type ClaimValidatorStakeRewardsResult struct { + CommonResult StakeStartBlock uint64 `serialize:"true" json:"stake_start_block"` StakeEndBlock uint64 `serialize:"true" json:"stake_end_block"` StakedAmount uint64 `serialize:"true" json:"staked_amount"` diff --git a/actions/complete_contribute_dataset.go b/actions/complete_contribute_dataset.go index 6fe3686..5bd9005 100644 --- a/actions/complete_contribute_dataset.go +++ b/actions/complete_contribute_dataset.go @@ -150,6 +150,7 @@ func (d *CompleteContributeDataset) Execute( } return &CompleteContributeDatasetResult{ + CommonResult: FillCommonResult(actor.String(), d.DatasetContributor.String()), CollateralAssetAddress: dataConfig.CollateralAssetAddressForDataContribution.String(), CollateralAmountRefunded: dataConfig.CollateralAmountForDataContribution, DatasetChildNftAddress: nftAddress.String(), @@ -182,6 +183,7 @@ var ( ) type CompleteContributeDatasetResult struct { + CommonResult CollateralAssetAddress string `serialize:"true" json:"collateral_asset_address"` CollateralAmountRefunded uint64 `serialize:"true" json:"collateral_amount_refunded"` DatasetChildNftAddress string `serialize:"true" json:"dataset_child_nft_address"` diff --git a/actions/contract_call.go b/actions/contract_call.go index 70d6257..ab3ddf0 100644 --- a/actions/contract_call.go +++ b/actions/contract_call.go @@ -86,7 +86,7 @@ func (t *ContractCall) Execute( return nil, err } consumedFuel := t.Fuel - callInfo.RemainingFuel() - return &ContractCallResult{Value: resultBytes, ConsumedFuel: consumedFuel}, nil + return &ContractCallResult{CommonResult: FillCommonResult(actor.String(), ""), Value: resultBytes, ConsumedFuel: consumedFuel}, nil } func (t *ContractCall) ComputeUnits(chain.Rules) uint64 { @@ -143,6 +143,7 @@ func UnmarshalCallContract(r *runtime.WasmRuntime) func(p *codec.Packer) (chain. var _ codec.Typed = (*ContractCallResult)(nil) type ContractCallResult struct { + CommonResult Value []byte `serialize:"true" json:"value"` ConsumedFuel uint64 `serialize:"true" json:"consumedfuel"` } diff --git a/actions/contract_deploy.go b/actions/contract_deploy.go index 61599ac..fce26e2 100644 --- a/actions/contract_deploy.go +++ b/actions/contract_deploy.go @@ -48,12 +48,12 @@ func (d *ContractDeploy) Execute( _ chain.Rules, mu state.Mutable, _ int64, - _ codec.Address, + actor codec.Address, _ ids.ID, ) (codec.Typed, error) { result, err := (&storage.ContractStateManager{Mutable: mu}). NewAccountWithContract(ctx, d.ContractID, d.CreationInfo) - return &ContractDeployResult{Address: result}, err + return &ContractDeployResult{CommonResult: FillCommonResult(actor.String(), ""), Address: result}, err } func (*ContractDeploy) ComputeUnits(chain.Rules) uint64 { @@ -94,6 +94,7 @@ var ( ) type ContractDeployResult struct { + CommonResult Address codec.Address `serialize:"true" json:"address"` } diff --git a/actions/contract_publish.go b/actions/contract_publish.go index af744a9..42c723a 100644 --- a/actions/contract_publish.go +++ b/actions/contract_publish.go @@ -48,14 +48,14 @@ func (t *ContractPublish) Execute( _ chain.Rules, mu state.Mutable, _ int64, - _ codec.Address, + actor codec.Address, _ ids.ID, ) (codec.Typed, error) { resultBytes, err := storage.StoreContract(ctx, mu, t.ContractBytes) if err != nil { return nil, err } - return &ContractPublishResult{Value: resultBytes}, nil + return &ContractPublishResult{CommonResult: FillCommonResult(actor.String(), ""), Value: resultBytes}, nil } func (*ContractPublish) ComputeUnits(chain.Rules) uint64 { @@ -90,6 +90,7 @@ func UnmarshalPublishContract(p *codec.Packer) (chain.Action, error) { var _ codec.Typed = (*ContractPublishResult)(nil) type ContractPublishResult struct { + CommonResult Value []byte `serialize:"true" json:"value"` } diff --git a/actions/create_asset.go b/actions/create_asset.go index 0d44d3b..634f545 100644 --- a/actions/create_asset.go +++ b/actions/create_asset.go @@ -136,6 +136,7 @@ func (c *CreateAsset) Execute( } output := CreateAssetResult{ + CommonResult: FillCommonResult(actor.String(), ""), AssetAddress: assetAddress.String(), AssetBalance: uint64(0), } @@ -154,6 +155,7 @@ func (c *CreateAsset) Execute( // Mint the parent NFT for the dataset(fractionalized asset) nftAddress := storage.AssetAddressNFT(assetAddress, []byte(c.Metadata), actor) output.DatasetParentNftAddress = nftAddress.String() + output.CommonResult.Receiver = actor.String() symbol := utils.CombineWithSuffix([]byte(c.Symbol), 0, storage.MaxSymbolSize) if err := storage.SetAssetInfo(ctx, mu, nftAddress, nconsts.AssetNonFungibleTokenID, []byte(c.Name), symbol, 0, []byte(c.Metadata), []byte(assetAddress.String()), 0, 1, actor, codec.EmptyAddress, codec.EmptyAddress, codec.EmptyAddress, codec.EmptyAddress); err != nil { return nil, err @@ -198,6 +200,7 @@ var ( ) type CreateAssetResult struct { + CommonResult AssetAddress string `serialize:"true" json:"asset_address"` AssetBalance uint64 `serialize:"true" json:"asset_balance"` DatasetParentNftAddress string `serialize:"true" json:"dataset_parent_nft_address"` diff --git a/actions/create_dataset.go b/actions/create_dataset.go index e3242ef..180324c 100644 --- a/actions/create_dataset.go +++ b/actions/create_dataset.go @@ -133,6 +133,7 @@ func (c *CreateDataset) Execute( } return &CreateDatasetResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), DatasetAddress: c.AssetAddress.String(), DatasetParentNftAddress: storage.AssetAddressNFT(c.AssetAddress, metadata, owner).String(), }, nil @@ -167,6 +168,7 @@ var ( ) type CreateDatasetResult struct { + CommonResult DatasetAddress string `serialize:"true" json:"dataset_address"` DatasetParentNftAddress string `serialize:"true" json:"dataset_parent_nft_address"` } diff --git a/actions/delegate_user_stake.go b/actions/delegate_user_stake.go index e1adacb..5baee06 100644 --- a/actions/delegate_user_stake.go +++ b/actions/delegate_user_stake.go @@ -126,6 +126,7 @@ func (s *DelegateUserStake) Execute( return nil, err } return &DelegateUserStakeResult{ + CommonResult: FillCommonResult(actor.String(), s.NodeID.String()), StakedAmount: s.StakedAmount, BalanceBeforeStake: balance, BalanceAfterStake: newBalance, @@ -175,6 +176,7 @@ var ( ) type DelegateUserStakeResult struct { + CommonResult StakedAmount uint64 `serialize:"true" json:"staked_amount"` BalanceBeforeStake uint64 `serialize:"true" json:"balance_before_stake"` BalanceAfterStake uint64 `serialize:"true" json:"balance_after_stake"` diff --git a/actions/initiate_contribute_dataset.go b/actions/initiate_contribute_dataset.go index d356d29..37a5635 100644 --- a/actions/initiate_contribute_dataset.go +++ b/actions/initiate_contribute_dataset.go @@ -125,6 +125,7 @@ func (d *InitiateContributeDataset) Execute( } return &InitiateContributeDatasetResult{ + CommonResult: FillCommonResult(actor.String(), ""), DatasetContributionID: datasetContributionID.String(), CollateralAssetAddress: dataConfig.CollateralAssetAddressForDataContribution.String(), CollateralAmountTaken: dataConfig.CollateralAmountForDataContribution, @@ -154,6 +155,7 @@ var ( ) type InitiateContributeDatasetResult struct { + CommonResult DatasetContributionID string `serialize:"true" json:"dataset_contribution_id"` CollateralAssetAddress string `serialize:"true" json:"collateral_asset_address"` CollateralAmountTaken uint64 `serialize:"true" json:"collateral_amount_taken"` diff --git a/actions/mint_asset_ft.go b/actions/mint_asset_ft.go index 4611a6e..dee42b8 100644 --- a/actions/mint_asset_ft.go +++ b/actions/mint_asset_ft.go @@ -85,8 +85,9 @@ func (m *MintAssetFT) Execute( } return &MintAssetFTResult{ - OldBalance: newBalance - m.Value, - NewBalance: newBalance, + CommonResult: FillCommonResult(actor.String(), m.To.String()), + OldBalance: newBalance - m.Value, + NewBalance: newBalance, }, nil } @@ -113,6 +114,7 @@ var ( ) type MintAssetFTResult struct { + CommonResult OldBalance uint64 `serialize:"true" json:"old_balance"` NewBalance uint64 `serialize:"true" json:"new_balance"` } diff --git a/actions/mint_asset_nft.go b/actions/mint_asset_nft.go index 3d7662d..8659db2 100644 --- a/actions/mint_asset_nft.go +++ b/actions/mint_asset_nft.go @@ -102,6 +102,7 @@ func (m *MintAssetNFT) Execute( } return &MintAssetNFTResult{ + CommonResult: FillCommonResult(actor.String(), m.To.String()), AssetNftAddress: nftAddress.String(), OldBalance: newBalance - 1, NewBalance: newBalance, @@ -131,6 +132,7 @@ var ( ) type MintAssetNFTResult struct { + CommonResult AssetNftAddress string `serialize:"true" json:"asset_nft_address"` OldBalance uint64 `serialize:"true" json:"old_balance"` NewBalance uint64 `serialize:"true" json:"new_balance"` diff --git a/actions/publish_dataset_marketplace.go b/actions/publish_dataset_marketplace.go index ef49966..82d1e69 100644 --- a/actions/publish_dataset_marketplace.go +++ b/actions/publish_dataset_marketplace.go @@ -104,6 +104,7 @@ func (d *PublishDatasetMarketplace) Execute( } return &PublishDatasetMarketplaceResult{ + CommonResult: FillCommonResult(actor.String(), ""), MarketplaceAssetAddress: marketplaceAssetAddress.String(), PaymentAssetAddress: d.PaymentAssetAddress.String(), DatasetPricePerBlock: d.DatasetPricePerBlock, @@ -134,6 +135,7 @@ var ( ) type PublishDatasetMarketplaceResult struct { + CommonResult MarketplaceAssetAddress string `serialize:"true" json:"marketplace_asset_address"` PaymentAssetAddress string `serialize:"true" json:"payment_asset_address"` Publisher string `serialize:"true" json:"publisher"` diff --git a/actions/register_validator_stake.go b/actions/register_validator_stake.go index 4c00ceb..f54dccd 100644 --- a/actions/register_validator_stake.go +++ b/actions/register_validator_stake.go @@ -172,6 +172,7 @@ func (r *RegisterValidatorStake) Execute( return nil, err } return &RegisterValidatorStakeResult{ + CommonResult: FillCommonResult(actor.String(), ""), NodeID: stakeInfo.NodeID.String(), StakeStartBlock: stakeInfo.StakeStartBlock, StakeEndBlock: stakeInfo.StakeEndBlock, @@ -272,6 +273,7 @@ var ( ) type RegisterValidatorStakeResult struct { + CommonResult NodeID string `serialize:"true" json:"node_id"` StakeStartBlock uint64 `serialize:"true" json:"stake_start_block"` StakeEndBlock uint64 `serialize:"true" json:"stake_end_block"` diff --git a/actions/result_helpers.go b/actions/result_helpers.go new file mode 100644 index 0000000..3f3ed71 --- /dev/null +++ b/actions/result_helpers.go @@ -0,0 +1,18 @@ +// Copyright (C) 2024, Nuklai. All rights reserved. +// See the file LICENSE for licensing terms. + +package actions + +// CommonResult holds the shared fields for action results +type CommonResult struct { + Actor string `serialize:"true" json:"actor"` + Receiver string `serialize:"true" json:"receiver"` +} + +// FillCommonResult fills the common fields for action results. +func FillCommonResult(actor, receiver string) CommonResult { + return CommonResult{ + Actor: actor, + Receiver: receiver, + } +} diff --git a/actions/subscribe_dataset_marketplace.go b/actions/subscribe_dataset_marketplace.go index 6b1b34d..7d1eb36 100644 --- a/actions/subscribe_dataset_marketplace.go +++ b/actions/subscribe_dataset_marketplace.go @@ -191,6 +191,7 @@ func (d *SubscribeDatasetMarketplace) Execute( } return &SubscribeDatasetMarketplaceResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), MarketplaceAssetAddress: d.MarketplaceAssetAddress.String(), MarketplaceAssetNumSubscriptions: prevSubscriptions + 1, SubscriptionNftAddress: nftAddress.String(), @@ -226,6 +227,7 @@ var ( ) type SubscribeDatasetMarketplaceResult struct { + CommonResult MarketplaceAssetAddress string `serialize:"true" json:"marketplace_asset_address"` MarketplaceAssetNumSubscriptions uint64 `serialize:"true" json:"marketplace_asset_num_subscriptions"` SubscriptionNftAddress string `serialize:"true" json:"subscription_nft_address"` diff --git a/actions/transfer.go b/actions/transfer.go index ba70676..ce3c528 100644 --- a/actions/transfer.go +++ b/actions/transfer.go @@ -100,6 +100,7 @@ func (t *Transfer) Execute( } return &TransferResult{ + CommonResult: FillCommonResult(actor.String(), t.To.String()), SenderBalance: senderBalance, ReceiverBalance: receiverBalance, }, nil @@ -129,6 +130,7 @@ var ( ) type TransferResult struct { + CommonResult SenderBalance uint64 `serialize:"true" json:"sender_balance"` ReceiverBalance uint64 `serialize:"true" json:"receiver_balance"` } diff --git a/actions/undelegate_user_stake.go b/actions/undelegate_user_stake.go index 5f9fee9..bfb7132 100644 --- a/actions/undelegate_user_stake.go +++ b/actions/undelegate_user_stake.go @@ -87,6 +87,7 @@ func (u *UndelegateUserStake) Execute( } return &UndelegateUserStakeResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), StakeStartBlock: stakeStartBlock, StakeEndBlock: stakeEndBlock, UnstakedAmount: stakedAmount, @@ -134,6 +135,7 @@ var ( ) type UndelegateUserStakeResult struct { + CommonResult StakeStartBlock uint64 `serialize:"true" json:"stake_start_block"` StakeEndBlock uint64 `serialize:"true" json:"stake_end_block"` UnstakedAmount uint64 `serialize:"true" json:"unstaked_amount"` diff --git a/actions/update_asset.go b/actions/update_asset.go index f5b4caf..b683c6e 100644 --- a/actions/update_asset.go +++ b/actions/update_asset.go @@ -113,6 +113,7 @@ func (u *UpdateAsset) Execute( } var updateAssetResult UpdateAssetResult + updateAssetResult.CommonResult = FillCommonResult(actor.String(), "") // if u.Name is passed, update the dataset name // otherwise, keep the existing name @@ -214,6 +215,7 @@ var ( ) type UpdateAssetResult struct { + CommonResult Name string `serialize:"true" json:"name"` Symbol string `serialize:"true" json:"symbol"` Metadata string `serialize:"true" json:"metadata"` diff --git a/actions/update_dataset.go b/actions/update_dataset.go index 5230423..acec365 100644 --- a/actions/update_dataset.go +++ b/actions/update_dataset.go @@ -84,6 +84,7 @@ func (u *UpdateDataset) Execute( } var updateDatasetResult UpdateDatasetResult + updateDatasetResult.CommonResult = FillCommonResult(actor.String(), "") // if u.Name is passed, update the dataset name // otherwise, keep the existing name @@ -176,6 +177,7 @@ var ( ) type UpdateDatasetResult struct { + CommonResult Name string `serialize:"true" json:"name"` Description string `serialize:"true" json:"description"` Categories string `serialize:"true" json:"categories"` diff --git a/actions/withdraw_validator_stake.go b/actions/withdraw_validator_stake.go index c87469e..7e401d6 100644 --- a/actions/withdraw_validator_stake.go +++ b/actions/withdraw_validator_stake.go @@ -97,6 +97,7 @@ func (u *WithdrawValidatorStake) Execute( } return &WithdrawValidatorStakeResult{ + CommonResult: FillCommonResult(actor.String(), actor.String()), StakeStartBlock: stakeStartBlock, StakeEndBlock: stakeEndBlock, UnstakedAmount: stakedAmount, @@ -145,6 +146,7 @@ var ( ) type WithdrawValidatorStakeResult struct { + CommonResult StakeStartBlock uint64 `serialize:"true" json:"stake_start_block"` StakeEndBlock uint64 `serialize:"true" json:"stake_end_block"` UnstakedAmount uint64 `serialize:"true" json:"unstaked_amount"`