Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for datasets #58

Merged
merged 52 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5767210
WIP: Added handlers for both fungible and non-fungible tokens
kpachhai Aug 15, 2024
91547b6
Fixed linting errors
kpachhai Aug 15, 2024
39e3d01
Fixed linting errors
kpachhai Aug 15, 2024
7595143
Fixed linting errors
kpachhai Aug 15, 2024
843b46b
Fixed linting errors
kpachhai Aug 15, 2024
5b054a5
Fixed the integration tests
kpachhai Aug 16, 2024
2417dd5
WIP: UPdated to use NFT id instead of asset id for storing
kpachhai Aug 16, 2024
3aff350
WIP: Updated asset info
kpachhai Aug 16, 2024
9f43f9a
Fixed an issue with minting nft
kpachhai Aug 19, 2024
8aa9fd6
Fixed linting errors
kpachhai Aug 19, 2024
2f75c33
Fixed linting errors
kpachhai Aug 19, 2024
eb7a01a
Created a new action for create_dataset
kpachhai Aug 19, 2024
40f0078
Added create dataset action and integration test
kpachhai Aug 20, 2024
b902e1e
Fixed lint error
kpachhai Aug 20, 2024
e0afb6d
Added create dataset to integration test
kpachhai Aug 21, 2024
e78cb6e
Added get-dataset to nuklai cli
kpachhai Aug 21, 2024
248e0fc
Refactored code for nuklai-cli
kpachhai Aug 21, 2024
20929e5
Refactored the logic for assettype for fungible, non-fungible and dat…
kpachhai Aug 22, 2024
8560113
Fixing lint error
kpachhai Aug 22, 2024
9cc9bb6
Fixing lint error
kpachhai Aug 22, 2024
38454e1
Fixing lint error
kpachhai Aug 22, 2024
240d332
Added a way to create dataset
kpachhai Aug 23, 2024
fac54d5
Fixed lint issue
kpachhai Aug 23, 2024
e21abee
Adde3d two new actions for updating asset and updating dataset
kpachhai Aug 26, 2024
6f9142f
Fixed some linting errors
kpachhai Aug 26, 2024
1181fd9
Fixed some linting errors
kpachhai Aug 26, 2024
c3a6c8f
Added storage option for storing nft collection info and WIP for mark…
kpachhai Sep 11, 2024
6bf583f
Fixed some lint errors
kpachhai Sep 11, 2024
04e9bc3
Separated different storage keys into different files
kpachhai Sep 12, 2024
0b2c707
Handling adding data row to dataset in a 2 step process
kpachhai Sep 12, 2024
dbba891
Fixed some lint errors
kpachhai Sep 12, 2024
b0b1ef1
Updated contribute dataset functions
kpachhai Sep 13, 2024
40cba66
Added a new getter function to retrieve contribution info
kpachhai Sep 13, 2024
ff74507
Fixed an issue with integration test with complte contribution
kpachhai Sep 13, 2024
d7f9766
Added GetDataContributionPendingInfo to retrieve info about pending c…
kpachhai Sep 16, 2024
dbaacd8
Fixed linter issue
kpachhai Sep 16, 2024
c69bb1a
Fixed an issue with GetDataContributionPendingInfo RPC API
kpachhai Sep 16, 2024
88c71d7
Merge pull request #55 from Nuklai/upgrade-asset-functionality
kpachhai Sep 16, 2024
5c31e79
Added publish dataset to action
kpachhai Sep 17, 2024
60a588f
Fixed lint errors
kpachhai Sep 17, 2024
c521e97
Split up integration tests to make it easier for local testing
kpachhai Sep 17, 2024
c3413a8
Added the new tests
kpachhai Sep 17, 2024
4421bac
Added publish and subscribe and added a new type of token - marketpal…
kpachhai Sep 17, 2024
3975a21
Fixing lint issues
kpachhai Sep 17, 2024
8ee81a0
Added subscribe dataset to integration test
kpachhai Sep 18, 2024
b81e2ed
Added tests for both publish and subscribe
kpachhai Sep 18, 2024
90350d9
Added basic claim feature to the subscription
kpachhai Sep 19, 2024
3ad78cc
Fixed linter issues
kpachhai Sep 19, 2024
3fb11fd
Updated the documentation
kpachhai Sep 19, 2024
d3f8940
Merge pull request #56 from Nuklai/publish-dataset
kpachhai Sep 19, 2024
16baf36
Now storing failed transactions on ledger
kpachhai Sep 20, 2024
ffc8369
Merge pull request #57 from Nuklai/store-failed-tx
kpachhai Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,4 @@ docker-compose -f trace/zipkin.yml down

## Creating a Devnet

Refer to [Creating Devnet Demo](./docs/demos/devnet.md) to learn how to create a private devnet (running on a
custom Primary Network with traffic scoped to the deployer IP) across any number of regions and nodes
in ~30 minutes with a single script.

/home/ubuntu/avalanche-node/avalanchego --config-file=/home/ubuntu/.avalanchego/configs/node.json
ubuntu@ip-172-31-39-145:~$ ps -p 10411 -o cmd
CMD
/home/ubuntu/.avalanchego/plugins/Nke3kc2vJZWmoVv3hewi3NYUCHa42wTvFuaX4j1sgNp8WCRX4

34.243.81.202
Refer to [Creating Devnet Demo](./docs/demos/devnet.md) to learn how to create a private devnet (running on a custom Primary Network with traffic scoped to the deployer IP) across any number of regions and nodes in ~30 minutes with a single script.
51 changes: 29 additions & 22 deletions actions/burn_asset.go → actions/burn_asset_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ import (
nconsts "github.com/nuklai/nuklaivm/consts"
)

var _ chain.Action = (*BurnAsset)(nil)
var _ chain.Action = (*BurnAssetFT)(nil)

type BurnAsset struct {
// Asset is the [TxID] that created the asset.
type BurnAssetFT struct {
// Asset ID of the asset to burn.
Asset ids.ID `json:"asset"`

// Number of assets to mint to [To].
// Number of assets to burn
Value uint64 `json:"value"`
}

func (*BurnAsset) GetTypeID() uint8 {
return nconsts.BurnAssetID
func (*BurnAssetFT) GetTypeID() uint8 {
return nconsts.BurnAssetFTID
}

func (b *BurnAsset) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
func (b *BurnAssetFT) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
return state.Keys{
string(storage.AssetKey(b.Asset)): state.Read | state.Write,
string(storage.BalanceKey(actor, b.Asset)): state.Read | state.Write,
}
}

func (*BurnAsset) StateKeysMaxChunks() []uint16 {
func (*BurnAssetFT) StateKeysMaxChunks() []uint16 {
return []uint16{storage.AssetChunks, storage.BalanceChunks}
}

func (b *BurnAsset) Execute(
func (b *BurnAssetFT) Execute(
ctx context.Context,
_ chain.Rules,
mu state.Mutable,
Expand All @@ -54,47 +54,54 @@ func (b *BurnAsset) Execute(
if b.Value == 0 {
return nil, ErrOutputValueZero
}
if err := storage.SubBalance(ctx, mu, actor, b.Asset, b.Value); err != nil {
return nil, err
}
exists, symbol, decimals, metadata, supply, owner, err := storage.GetAsset(ctx, mu, b.Asset)

exists, assetType, name, symbol, decimals, metadata, uri, totalSupply, maxSupply, admin, mintActor, pauseUnpauseActor, freezeUnfreezeActor, enableDisableKYCAccountActor, err := storage.GetAsset(ctx, mu, b.Asset)
if err != nil {
return nil, err
}
if !exists {
return nil, ErrOutputAssetMissing
}
newSupply, err := smath.Sub(supply, b.Value)
if assetType != nconsts.AssetFungibleTokenID {
return nil, ErrOutputWrongAssetType
}

newSupply, err := smath.Sub(totalSupply, b.Value)
if err != nil {
return nil, err
}
if err := storage.SetAsset(ctx, mu, b.Asset, symbol, decimals, metadata, newSupply, owner); err != nil {
if err := storage.SetAsset(ctx, mu, b.Asset, assetType, name, symbol, decimals, metadata, uri, newSupply, maxSupply, admin, mintActor, pauseUnpauseActor, freezeUnfreezeActor, enableDisableKYCAccountActor); err != nil {
return nil, err
}

if err := storage.SubBalance(ctx, mu, actor, b.Asset, b.Value); err != nil {
return nil, err
}

return nil, nil
}

func (*BurnAsset) ComputeUnits(chain.Rules) uint64 {
func (*BurnAssetFT) ComputeUnits(chain.Rules) uint64 {
return BurnAssetComputeUnits
}

func (*BurnAsset) Size() int {
func (*BurnAssetFT) Size() int {
return ids.IDLen + consts.Uint64Len
}

func (b *BurnAsset) Marshal(p *codec.Packer) {
func (b *BurnAssetFT) Marshal(p *codec.Packer) {
p.PackID(b.Asset)
p.PackUint64(b.Value)
}

func UnmarshalBurnAsset(p *codec.Packer) (chain.Action, error) {
var burn BurnAsset
func UnmarshalBurnAssetFT(p *codec.Packer) (chain.Action, error) {
var burn BurnAssetFT
p.UnpackID(false, &burn.Asset) // can burn native asset
burn.Value = p.UnpackUint64(true)
burn.Value = p.UnpackUint64(false)
return &burn, p.Err()
}

func (*BurnAsset) ValidRange(chain.Rules) (int64, int64) {
func (*BurnAssetFT) ValidRange(chain.Rules) (int64, int64) {
// Returning -1, -1 means that the action is always valid.
return -1, -1
}
121 changes: 121 additions & 0 deletions actions/burn_asset_nft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (C) 2024, Nuklai. All rights reserved.
// See the file LICENSE for licensing terms.

package actions

import (
"context"

"github.com/ava-labs/avalanchego/ids"
smath "github.com/ava-labs/avalanchego/utils/math"

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/state"
"github.com/nuklai/nuklaivm/storage"

nconsts "github.com/nuklai/nuklaivm/consts"
)

var _ chain.Action = (*BurnAssetNFT)(nil)

type BurnAssetNFT struct {
// Asset ID of the asset to burn(this is the nft collection ID)
Asset ids.ID `json:"asset"`

// NFT ID of the asset to burn
NftID ids.ID `json:"nftID"`
}

func (*BurnAssetNFT) GetTypeID() uint8 {
return nconsts.BurnAssetNFTID
}

func (b *BurnAssetNFT) StateKeys(actor codec.Address, _ ids.ID) state.Keys {
return state.Keys{
string(storage.AssetKey(b.Asset)): state.Read | state.Write,
string(storage.AssetNFTKey(b.NftID)): state.Read | state.Write,
string(storage.BalanceKey(actor, b.Asset)): state.Read | state.Write,
string(storage.BalanceKey(actor, b.NftID)): state.Read | state.Write,
}
}

func (*BurnAssetNFT) StateKeysMaxChunks() []uint16 {
return []uint16{storage.AssetChunks, storage.AssetNFTChunks, storage.BalanceChunks, storage.BalanceChunks}
}

func (b *BurnAssetNFT) Execute(
ctx context.Context,
_ chain.Rules,
mu state.Mutable,
_ int64,
actor codec.Address,
_ ids.ID,
) ([][]byte, error) {
exists, assetType, name, symbol, decimals, metadata, uri, totalSupply, maxSupply, admin, mintActor, pauseUnpauseActor, freezeUnfreezeActor, enableDisableKYCAccountActor, err := storage.GetAsset(ctx, mu, b.Asset)
if err != nil {
return nil, err
}
if !exists {
return nil, ErrOutputAssetMissing
}
if assetType != nconsts.AssetNonFungibleTokenID {
return nil, ErrOutputWrongAssetType
}

exists, _, _, _, _, _, err = storage.GetAssetNFT(ctx, mu, b.NftID)
if err != nil {
return nil, err
}
if !exists {
return nil, ErrOutputAssetMissing
}

amountOfToken := uint64(1)
newSupply, err := smath.Sub(totalSupply, amountOfToken)
if err != nil {
return nil, err
}
if err := storage.SetAsset(ctx, mu, b.Asset, assetType, name, symbol, decimals, metadata, uri, newSupply, maxSupply, admin, mintActor, pauseUnpauseActor, freezeUnfreezeActor, enableDisableKYCAccountActor); err != nil {
return nil, err
}

if err := storage.DeleteAssetNFT(ctx, mu, b.NftID); err != nil {
return nil, err
}
if err := storage.SubBalance(ctx, mu, actor, b.NftID, 1); err != nil {
return nil, err
}

// Sub balance from collection
if err := storage.SubBalance(ctx, mu, actor, b.Asset, amountOfToken); err != nil {
return nil, err
}

return nil, nil
}

func (*BurnAssetNFT) ComputeUnits(chain.Rules) uint64 {
return BurnAssetComputeUnits
}

func (*BurnAssetNFT) Size() int {
return ids.IDLen * 2
}

func (b *BurnAssetNFT) Marshal(p *codec.Packer) {
p.PackID(b.Asset)
p.PackID(b.NftID)
}

func UnmarshalBurnAssetNFT(p *codec.Packer) (chain.Action, error) {
var burn BurnAssetNFT
p.UnpackID(false, &burn.Asset)
p.UnpackID(false, &burn.NftID)
return &burn, p.Err()
}

func (*BurnAssetNFT) ValidRange(chain.Rules) (int64, int64) {
// Returning -1, -1 means that the action is always valid.
return -1, -1
}
3 changes: 3 additions & 0 deletions actions/claim_delegation_stake_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (c *ClaimDelegationStakeRewards) Execute(
if err != nil {
return nil, ErrOutputInvalidNodeID
}
if _, err := codec.AddressBech32(nconsts.HRP, c.UserStakeAddress); err != nil {
return nil, err
}

exists, stakeStartBlock, _, _, rewardAddress, _, _ := storage.GetDelegateUserStake(ctx, mu, c.UserStakeAddress, nodeID)
if !exists {
Expand Down
Loading
Loading