@@ -2,7 +2,6 @@ package providercontract
22
33import (
44 "context"
5- "fmt"
65 "math/big"
76
87 "github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -46,7 +45,7 @@ func (c *ProviderContract) OccupyService(ctx context.Context, service config.Ser
4645func (c * ProviderContract ) AddOrUpdateService (ctx context.Context , service config.Service , occupied bool ) error {
4746 // Get existing service if any
4847 old , err := c .GetService (ctx )
49- if err != nil && err . Error () != "service not found" {
48+ if err != nil && ! IsServiceNotExist ( err ) {
5049 return errors .Wrap (err , "get service from contract" )
5150 }
5251
@@ -88,7 +87,14 @@ func (c *ProviderContract) addOrUpdateServiceWithOld(ctx context.Context, servic
8887 if old == nil {
8988 // First-time registration: need to stake
9089 stakeValue = DefaultProviderStake
91- c .logger .Infof ("First-time service registration, staking %s" , stakeValue .String ())
90+ if service .ProviderStake != "" {
91+ stakeValue , err = util .ConvertToBigInt (service .ProviderStake )
92+ if err != nil {
93+ c .logger .Errorf ("[addOrUpdateServiceWithOld] Failed to convert provider stake - stake=%s, error=%v" , service .ProviderStake , err )
94+ return errors .Wrap (err , "convert provider stake" )
95+ }
96+ }
97+ c .logger .Infof ("[addOrUpdateServiceWithOld] First-time service registration, stake amount: %s" , stakeValue .String ())
9298 }
9399 // If old exists, it's an update, stakeValue remains nil (no additional stake)
94100
@@ -154,26 +160,29 @@ func (c *ProviderContract) DeleteService(ctx context.Context) error {
154160}
155161
156162func (c * ProviderContract ) GetService (ctx context.Context ) (* contract.Service , error ) {
163+ c .logger .Infof ("[GetService] Starting to get service - provider=%s" , c .ProviderAddress )
164+
157165 callOpts := & bind.CallOpts {
158166 Context : ctx ,
159167 }
160168
161- list , err := c .Contract .GetAllServices (callOpts )
169+ service , err := c .Contract .GetService (callOpts , common . HexToAddress ( c . ProviderAddress ) )
162170 if err != nil {
163- return nil , err
164- }
165- for i := range list {
166- if list [i ].Provider .String () == c .ProviderAddress {
167- return & list [i ], nil
168- }
171+ // Wrap error to extract details from rpc.jsonError Data field
172+ wrappedErr := WrapContractError (err )
173+ c .logger .Errorf ("[GetService] Contract error - provider=%s: %v" , c .ProviderAddress , wrappedErr )
174+ return nil , wrappedErr
169175 }
170176
171- return nil , fmt .Errorf ("service not found" )
177+ c .logger .Infof ("[GetService] Retrieved service from contract - url=%s, models=%v, pricePerToken=%s, occupied=%v" ,
178+ service .Url , service .Models , service .PricePerToken .String (), service .Occupied )
179+
180+ return & service , nil
172181}
173182
174183func (c * ProviderContract ) SyncServices (ctx context.Context , new config.Service ) error {
175184 old , err := c .GetService (ctx )
176- if err != nil && err . Error () != "service not found" {
185+ if err != nil && ! IsServiceNotExist ( err ) {
177186 return err
178187 }
179188
0 commit comments