Skip to content

Commit

Permalink
feat(TCK): Implement token update and delete (#1169)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov authored Dec 5, 2024
1 parent 0cdd585 commit 909c99c
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tck/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func main() {
"updateAccount": postHandler(HandleError, handler.New(accountService.UpdateAccount)),
"deleteAccount": postHandler(HandleError, handler.New(accountService.DeleteAccount)),
"createToken": postHandler(HandleError, handler.New(tokenService.CreateToken)),
"updateToken": postHandler(HandleError, handler.New(tokenService.UpdateToken)),
"deleteToken": postHandler(HandleError, handler.New(tokenService.DeleteToken)),
"generateKey": postHandler(HandleError, handler.New(methods.GenerateKey)),
}

Expand Down
2 changes: 1 addition & 1 deletion tck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/creachadair/jrpc2 v1.1.2
github.com/hiero-ledger/hiero-sdk-go/v2 v2.42.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
)

replace github.com/hiero-ledger/hiero-sdk-go/v2 => ../
Expand Down
4 changes: 2 additions & 2 deletions tck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
Expand Down
160 changes: 160 additions & 0 deletions tck/methods/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,163 @@ func (t *TokenService) CreateToken(_ context.Context, params param.CreateTokenPa

return &response.TokenResponse{TokenId: receipt.TokenID.String(), Status: receipt.Status.String()}, nil
}

// UpdateToken jRPC method for updateToken
func (t *TokenService) UpdateToken(_ context.Context, params param.UpdateTokenParams) (*response.TokenResponse, error) {

transaction := hiero.NewTokenUpdateTransaction().SetGrpcDeadline(&threeSecondsDuration)

if params.TokenId != nil {
tokenId, err := hiero.TokenIDFromString(*params.TokenId)
if err != nil {
return nil, err
}
transaction.SetTokenID(tokenId)
}
if params.AdminKey != nil {
key, err := utils.GetKeyFromString(*params.AdminKey)
if err != nil {
return nil, err
}
transaction.SetAdminKey(key)
}

if params.KycKey != nil {
key, err := utils.GetKeyFromString(*params.KycKey)
if err != nil {
return nil, err
}
transaction.SetKycKey(key)
}

if params.FreezeKey != nil {
key, err := utils.GetKeyFromString(*params.FreezeKey)
if err != nil {
return nil, err
}
transaction.SetFreezeKey(key)
}

if params.WipeKey != nil {
key, err := utils.GetKeyFromString(*params.WipeKey)
if err != nil {
return nil, err
}
transaction.SetWipeKey(key)
}

if params.PauseKey != nil {
key, err := utils.GetKeyFromString(*params.PauseKey)
if err != nil {
return nil, err
}
transaction.SetPauseKey(key)
}

if params.MetadataKey != nil {
key, err := utils.GetKeyFromString(*params.MetadataKey)
if err != nil {
return nil, err
}
transaction.SetMetadataKey(key)
}

if params.SupplyKey != nil {
key, err := utils.GetKeyFromString(*params.SupplyKey)
if err != nil {
return nil, err
}
transaction.SetSupplyKey(key)
}

if params.FeeScheduleKey != nil {
key, err := utils.GetKeyFromString(*params.FeeScheduleKey)
if err != nil {
return nil, err
}
transaction.SetFeeScheduleKey(key)
}

if params.Name != nil {
transaction.SetTokenName(*params.Name)
}
if params.Symbol != nil {
transaction.SetTokenSymbol(*params.Symbol)
}
if params.Memo != nil {
transaction.SetTokenMemo(*params.Memo)
}
if params.TreasuryAccountId != nil {
accountID, err := hiero.AccountIDFromString(*params.TreasuryAccountId)
if err != nil {
return nil, err
}
transaction.SetTreasuryAccountID(accountID)
}
if params.ExpirationTime != nil {
expirationTime, err := strconv.ParseInt(*params.ExpirationTime, 10, 64)
if err != nil {
return nil, err
}
transaction.SetExpirationTime(time.Unix(expirationTime, 0))
}
if params.AutoRenewAccountId != nil {
autoRenewAccountId, err := hiero.AccountIDFromString(*params.AutoRenewAccountId)
if err != nil {
return nil, err
}
transaction.SetAutoRenewAccount(autoRenewAccountId)
}
if params.AutoRenewPeriod != nil {
autoRenewPeriodSeconds, err := strconv.ParseInt(*params.AutoRenewPeriod, 10, 64)
if err != nil {
return nil, err
}
transaction.SetAutoRenewPeriod(time.Duration(autoRenewPeriodSeconds) * time.Second)
}

if params.Metadata != nil {
transaction.SetTokenMetadata([]byte(*params.Metadata))
}

if params.CommonTransactionParams != nil {
params.CommonTransactionParams.FillOutTransaction(transaction, t.sdkService.Client)
}

txResponse, err := transaction.Execute(t.sdkService.Client)
if err != nil {
return nil, err
}
receipt, err := txResponse.GetReceipt(t.sdkService.Client)
if err != nil {
return nil, err
}

return &response.TokenResponse{Status: receipt.Status.String()}, nil
}

// DeleteToken jRPC method for deleteToken
func (t *TokenService) DeleteToken(_ context.Context, params param.DeleteTokenParams) (*response.TokenResponse, error) {

transaction := hiero.NewTokenDeleteTransaction().SetGrpcDeadline(&threeSecondsDuration)
if params.TokenId != nil {
tokenId, err := hiero.TokenIDFromString(*params.TokenId)
if err != nil {
return nil, err
}
transaction.SetTokenID(tokenId)
}
if params.CommonTransactionParams != nil {
params.CommonTransactionParams.FillOutTransaction(transaction, t.sdkService.Client)
}
txResponse, err := transaction.Execute(t.sdkService.Client)
if err != nil {
return nil, err
}
receipt, err := txResponse.GetReceipt(t.sdkService.Client)
if err != nil {
return nil, err
}

return &response.TokenResponse{Status: receipt.Status.String()}, nil
}
26 changes: 26 additions & 0 deletions tck/param/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,29 @@ type CreateTokenParams struct {
Metadata *string `json:"metadata,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}

type UpdateTokenParams struct {
TokenId *string `json:"tokenId,omitempty"`
Name *string `json:"name,omitempty"`
Symbol *string `json:"symbol,omitempty"`
TreasuryAccountId *string `json:"treasuryAccountId,omitempty"`
AdminKey *string `json:"adminKey,omitempty"`
KycKey *string `json:"kycKey,omitempty"`
FreezeKey *string `json:"freezeKey,omitempty"`
WipeKey *string `json:"wipeKey,omitempty"`
SupplyKey *string `json:"supplyKey,omitempty"`
FeeScheduleKey *string `json:"feeScheduleKey,omitempty"`
PauseKey *string `json:"pauseKey,omitempty"`
MetadataKey *string `json:"metadataKey,omitempty"`
ExpirationTime *string `json:"expirationTime,omitempty"`
AutoRenewAccountId *string `json:"autoRenewAccountId,omitempty"`
AutoRenewPeriod *string `json:"autoRenewPeriod,omitempty"`
Memo *string `json:"memo,omitempty"`
Metadata *string `json:"metadata,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}

type DeleteTokenParams struct {
TokenId *string `json:"tokenId,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}

0 comments on commit 909c99c

Please sign in to comment.