Skip to content

Commit

Permalink
Added actor and receiver to each action output
Browse files Browse the repository at this point in the history
  • Loading branch information
kpachhai committed Dec 13, 2024
1 parent 9fd87b8 commit b17fd29
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 11 deletions.
6 changes: 4 additions & 2 deletions actions/burn_asset_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -97,6 +98,7 @@ var (
)

type BurnAssetFTResult struct {
CommonResult
OldBalance uint64 `serialize:"true" json:"old_balance"`
NewBalance uint64 `serialize:"true" json:"new_balance"`
}
Expand Down
6 changes: 4 additions & 2 deletions actions/burn_asset_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -113,6 +114,7 @@ var (
)

type BurnAssetNFTResult struct {
CommonResult
OldBalance uint64 `serialize:"true" json:"old_balance"`
NewBalance uint64 `serialize:"true" json:"new_balance"`
}
Expand Down
2 changes: 2 additions & 0 deletions actions/claim_delegation_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (c *ClaimDelegationStakeRewards) Execute(
}

return &ClaimDelegationStakeRewardsResult{
CommonResult: FillCommonResult(actor.String(), actor.String()),
StakeStartBlock: stakeStartBlock,
StakeEndBlock: stakeEndBlock,
StakedAmount: stakedAmount,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/claim_marketplace_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (c *ClaimMarketplacePayment) Execute(
}

return &ClaimMarketplacePaymentResult{
CommonResult: FillCommonResult(actor.String(), actor.String()),
LastClaimedBlock: lastClaimedBlock,
PaymentClaimed: paymentClaimed,
PaymentRemaining: paymentRemaining,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/claim_validator_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (c *ClaimValidatorStakeRewards) Execute(
}

return &ClaimValidatorStakeRewardsResult{
CommonResult: FillCommonResult(actor.String(), actor.String()),
StakeStartBlock: stakeStartBlock,
StakeEndBlock: stakeEndBlock,
StakedAmount: stakeAmount,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/complete_contribute_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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"`
Expand Down
3 changes: 2 additions & 1 deletion actions/contract_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
}
Expand Down
5 changes: 3 additions & 2 deletions actions/contract_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -94,6 +94,7 @@ var (
)

type ContractDeployResult struct {
CommonResult
Address codec.Address `serialize:"true" json:"address"`
}

Expand Down
5 changes: 3 additions & 2 deletions actions/contract_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
}

Expand Down
3 changes: 3 additions & 0 deletions actions/create_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (c *CreateAsset) Execute(
}

output := CreateAssetResult{
CommonResult: FillCommonResult(actor.String(), ""),
AssetAddress: assetAddress.String(),
AssetBalance: uint64(0),
}
Expand All @@ -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
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/create_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}
Expand Down
2 changes: 2 additions & 0 deletions actions/delegate_user_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/initiate_contribute_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (d *InitiateContributeDataset) Execute(
}

return &InitiateContributeDatasetResult{
CommonResult: FillCommonResult(actor.String(), ""),
DatasetContributionID: datasetContributionID.String(),
CollateralAssetAddress: dataConfig.CollateralAssetAddressForDataContribution.String(),
CollateralAmountTaken: dataConfig.CollateralAmountForDataContribution,
Expand Down Expand Up @@ -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"`
Expand Down
6 changes: 4 additions & 2 deletions actions/mint_asset_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -113,6 +114,7 @@ var (
)

type MintAssetFTResult struct {
CommonResult
OldBalance uint64 `serialize:"true" json:"old_balance"`
NewBalance uint64 `serialize:"true" json:"new_balance"`
}
Expand Down
2 changes: 2 additions & 0 deletions actions/mint_asset_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/publish_dataset_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (d *PublishDatasetMarketplace) Execute(
}

return &PublishDatasetMarketplaceResult{
CommonResult: FillCommonResult(actor.String(), ""),
MarketplaceAssetAddress: marketplaceAssetAddress.String(),
PaymentAssetAddress: d.PaymentAssetAddress.String(),
DatasetPricePerBlock: d.DatasetPricePerBlock,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/register_validator_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"`
Expand Down
18 changes: 18 additions & 0 deletions actions/result_helpers.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
2 changes: 2 additions & 0 deletions actions/subscribe_dataset_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (t *Transfer) Execute(
}

return &TransferResult{
CommonResult: FillCommonResult(actor.String(), t.To.String()),
SenderBalance: senderBalance,
ReceiverBalance: receiverBalance,
}, nil
Expand Down Expand Up @@ -129,6 +130,7 @@ var (
)

type TransferResult struct {
CommonResult
SenderBalance uint64 `serialize:"true" json:"sender_balance"`
ReceiverBalance uint64 `serialize:"true" json:"receiver_balance"`
}
Expand Down
2 changes: 2 additions & 0 deletions actions/undelegate_user_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (u *UndelegateUserStake) Execute(
}

return &UndelegateUserStakeResult{
CommonResult: FillCommonResult(actor.String(), actor.String()),
StakeStartBlock: stakeStartBlock,
StakeEndBlock: stakeEndBlock,
UnstakedAmount: stakedAmount,
Expand Down Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions actions/update_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Expand Down
Loading

0 comments on commit b17fd29

Please sign in to comment.