Skip to content

Commit

Permalink
feat(TCK): implement token schedule update (#1171)
Browse files Browse the repository at this point in the history
* feat: implement token update and delete

Signed-off-by: Ivan Ivanov <[email protected]>

* feat: add updateTokenFeeSchedule method

Signed-off-by: Ivan Ivanov <[email protected]>

* chore: refactor

Signed-off-by: Ivan Ivanov <[email protected]>

---------

Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov authored Dec 13, 2024
1 parent b09fac4 commit e3d3b65
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 25 deletions.
19 changes: 10 additions & 9 deletions tck/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ func main() {

// Create a new RPC server
assigner := handler.Map{
"setup": postHandler(HandleError, handler.New(sdkService.Setup)),
"reset": postHandler(HandleError, handler.New(sdkService.Reset)),
"createAccount": postHandler(HandleError, handler.New(accountService.CreateAccount)),
"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)),
"setup": postHandler(HandleError, handler.New(sdkService.Setup)),
"reset": postHandler(HandleError, handler.New(sdkService.Reset)),
"createAccount": postHandler(HandleError, handler.New(accountService.CreateAccount)),
"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)),
"updateTokenFeeSchedule": postHandler(HandleError, handler.New(tokenService.UpdateTokenFeeSchedule)),
"generateKey": postHandler(HandleError, handler.New(methods.GenerateKey)),
}

bridge := jhttp.NewBridge(assigner, nil)
Expand Down
8 changes: 4 additions & 4 deletions tck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ require (
github.com/rs/zerolog v1.33.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
Expand Down
16 changes: 8 additions & 8 deletions tck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
Expand Down
34 changes: 34 additions & 0 deletions tck/methods/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,37 @@ func (t *TokenService) DeleteToken(_ context.Context, params param.DeleteTokenPa

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

// UpdateTokenFeeSchedule jRPC method for updateTokenFeeSchedule
func (t *TokenService) UpdateTokenFeeSchedule(_ context.Context, params param.UpdateTokenFeeScheduleParams) (*response.TokenResponse, error) {
transaction := hiero.NewTokenFeeScheduleUpdateTransaction().SetGrpcDeadline(&threeSecondsDuration)

if params.TokenId != nil {
tokenId, err := hiero.TokenIDFromString(*params.TokenId)
if err != nil {
return nil, err
}
transaction.SetTokenID(tokenId)
}
if params.CustomFees != nil {
customFees, err := utils.ParseCustomFees(*params.CustomFees)
if err != nil {
return nil, err
}
transaction.SetCustomFees(customFees)
}
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
}
9 changes: 5 additions & 4 deletions tck/param/custom_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ type FixedFee struct {

// FractionalFee represents the fractional fee structure.
type FractionalFee struct {
Numerator string `json:"numerator"`
Denominator string `json:"denominator"`
MinimumAmount string `json:"minimumAmount"`
MaximumAmount string `json:"maximumAmount"`
Numerator string `json:"numerator"`
Denominator string `json:"denominator"`
MinimumAmount string `json:"minimumAmount"`
MaximumAmount string `json:"maximumAmount"`
AssessmentMethod string `json:"assessmentMethod"`
}

// RoyaltyFee represents the royalty fee structure.
Expand Down
6 changes: 6 additions & 0 deletions tck/param/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ type DeleteTokenParams struct {
TokenId *string `json:"tokenId,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
}

type UpdateTokenFeeScheduleParams struct {
TokenId *string `json:"tokenId,omitempty"`
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
CustomFees *[]CustomFee `json:"customFees,omitempty"`
}
5 changes: 5 additions & 0 deletions tck/utils/custom_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func ParseCustomFees(paramFees []param.CustomFee) ([]hiero.Fee, error) {
if err != nil {
return nil, err
}
if customFee.FractionalFee.AssessmentMethod == "inclusive" {
fee.SetAssessmentMethod(hiero.FeeAssessmentMethodInclusive)
} else {
fee.SetAssessmentMethod(hiero.FeeAssessmentMethodExclusive)
}
fee.SetFeeCollectorAccountID(feeCollector)
fee.SetAllCollectorsAreExempt(*customFee.FeeCollectorsExempt)
customFeeList = append(customFeeList, fee)
Expand Down

0 comments on commit e3d3b65

Please sign in to comment.