Skip to content

Commit

Permalink
gofmt and fix misspell
Browse files Browse the repository at this point in the history
  • Loading branch information
semyon-dev committed Jul 25, 2024
1 parent 4793c88 commit 11a79fa
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 145 deletions.
18 changes: 9 additions & 9 deletions authutils/auth_service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// authutils package provides functions for all authentication and singature validation related operations
// Package authutils provides functions for all authentication and signature validation related operations
package authutils

import (
Expand Down Expand Up @@ -67,21 +67,21 @@ func GetSignerAddressFromMessage(message, signature []byte) (signer *common.Addr
return &keyOwnerAddress, nil
}

// Verify the signature done by given singer or not
// returns nil if signer indeed sign the message and singature proves it, if not throws an error
// VerifySigner Verify the signature done by given singer or not
// returns nil if signer indeed sign the message and signature proves it, if not throws an error
func VerifySigner(message []byte, signature []byte, signer common.Address) error {
signerFromMessage, err := GetSignerAddressFromMessage(message, signature)
if err != nil {
zap.L().Error("Gering error from getSignerAddressFromMessage", zap.Error(err))
zap.L().Error("error from getSignerAddressFromMessage", zap.Error(err))
return err
}
if signerFromMessage.String() == signer.String() {
return nil
}
return fmt.Errorf("Incorrect signer.")
return fmt.Errorf("incorrect signer")
}

// Check if the block number passed is not more +- 5 from the latest block number on chain
// CompareWithLatestBlockNumber Check if the block number passed is not more +- 5 from the latest block number on chain
func CompareWithLatestBlockNumber(blockNumberPassed *big.Int) error {
latestBlockNumber, err := CurrentBlock()
if err != nil {
Expand All @@ -94,7 +94,7 @@ func CompareWithLatestBlockNumber(blockNumberPassed *big.Int) error {
return nil
}

// Check if the block number ( date on which the token was issued is not more than 1 month)
// CheckIfTokenHasExpired Check if the block number ( date on which the token was issued is not more than 1 month)
func CheckIfTokenHasExpired(expiredBlock *big.Int) error {
currentBlockNumber, err := CurrentBlock()
if err != nil {
Expand All @@ -107,7 +107,7 @@ func CheckIfTokenHasExpired(expiredBlock *big.Int) error {
return nil
}

// Get the current block number from on chain
// CurrentBlock Get the current block number from on chain
func CurrentBlock() (*big.Int, error) {
if ethClient, err := blockchain.GetEthereumClient(); err != nil {
return nil, err
Expand All @@ -122,7 +122,7 @@ func CurrentBlock() (*big.Int, error) {
}
}

// Check if the payment address/signer passed matches to what is present in the metadata
// VerifyAddress Check if the payment address/signer passed matches to what is present in the metadata
func VerifyAddress(address common.Address, otherAddress common.Address) error {
isSameAddress := otherAddress == address
if !isSameAddress {
Expand Down
2 changes: 1 addition & 1 deletion authutils/auth_service_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// authutils package provides functions for all authentication and singature validation related operations
// authutils package provides functions for all authentication and signature validation related operations
package authutils

import (
Expand Down
10 changes: 5 additions & 5 deletions blockchain/orginzationMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ func InitOrganizationMetaDataFromJson(jsonData string) (metaData *OrganizationMe
metaData = new(OrganizationMetaData)
err = json.Unmarshal([]byte(jsonData), &metaData)
if err != nil {
zap.L().Error("Error in unmarshaling metadata json", zap.Error(err), zap.Any("jsondata", jsonData))
zap.L().Error("Error in unmarshalling metadata json", zap.Error(err), zap.Any("jsondata", jsonData))
return nil, err
}

//Check for mandatory validations
// Check for mandatory validations

if err = setDerivedAttributes(metaData); err != nil {
zap.L().Error("Error in setting derived atrributes", zap.Error(err))
zap.L().Error("Error in setting derived attributes", zap.Error(err))
return nil, err
}
if err = checkMandatoryFields(metaData); err != nil {
zap.L().Error("Error in check mdandatory fields", zap.Error(err))
zap.L().Error("Error in check mandatory fields", zap.Error(err))
return nil, err
}

Expand All @@ -126,7 +126,7 @@ func checkMandatoryFields(metaData *OrganizationMetaData) (err error) {
err = fmt.Errorf("Mandatory field : ETCD Client Endpoints are mising for the Group %v ", metaData.daemonGroup.GroupName)
}
if &metaData.recipientPaymentAddress == nil {
err = fmt.Errorf("Mandatory field : Recepient Address is missing for the Group %v ", metaData.daemonGroup.GroupName)
err = fmt.Errorf("Mandatory field : Recipient Address is missing for the Group %v ", metaData.daemonGroup.GroupName)
}
return
}
Expand Down
11 changes: 5 additions & 6 deletions config/configuration_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ func Test_getLeafNodeKey(t *testing.T) {
}

func TestGetSchemaConfiguration(t *testing.T) {
schemaDetails,err := GetConfigurationSchema()
for _,element := range schemaDetails {
if (element.Name == "blockchain_network_selected") {
assert.Equal(t,element.DefaultValue,"local")
schemaDetails, err := GetConfigurationSchema()
for _, element := range schemaDetails {
if element.Name == "blockchain_network_selected" {
assert.Equal(t, element.DefaultValue, "local")
}
}
assert.Nil(t,err)
assert.Nil(t, err)
}

23 changes: 10 additions & 13 deletions configuration_service/broadcast_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,39 @@ import (
type MessageBroadcaster struct {
//Operator UI can trigger changes to the Daemon configuration or request the Daemon to stop/start processing requests will ,
// Hence we need a framework to receive this trigger and broadcast it to all the subscribers.
trigger chan int
quit chan int
trigger chan int
quit chan int
subscribers []chan int
//This will be used to make sure , we dont interfere with other threads
mutex sync.Mutex
mutex sync.Mutex
}


func NewChannelBroadcaster() *MessageBroadcaster {
broadcaster := &MessageBroadcaster{}
broadcaster.trigger = make(chan int,1)
broadcaster.trigger = make(chan int, 1)
go broadcaster.Publish()
return broadcaster
}


//Create a New Subscriber for this broadcaster message
//Interceptors or health checks can subscribe to this and react accordingly
// Create a New Subscriber for this broadcaster message
// Interceptors or health checks can subscribe to this and react accordingly
func (broadcast *MessageBroadcaster) NewSubscriber() chan int {
ch := make(chan int, 1)
broadcast.mutex.Lock()
defer broadcast.mutex.Unlock()
if broadcast.subscribers == nil {
broadcast.subscribers = make([]chan int,0)
broadcast.subscribers = make([]chan int, 0)
}
broadcast.subscribers = append(broadcast.subscribers, ch)

return ch
}


//Once a message is received, pass it down to all the subscribers
// Once a message is received, pass it down to all the subscribers
func (broadcast *MessageBroadcaster) Publish() {
for {
//Wait for the message to trigger the broadcast
msg := <- broadcast.trigger
msg := <-broadcast.trigger
broadcast.mutex.Lock()
defer broadcast.mutex.Unlock()
for _, subscriber := range broadcast.subscribers {
Expand All @@ -51,4 +48,4 @@ func (broadcast *MessageBroadcaster) Publish() {
}

}
}
}
15 changes: 7 additions & 8 deletions configuration_service/broadcast_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ func TestNewChannelBroadcaster(t *testing.T) {

func TestChannelBroadcaster_NewSubscriber(t *testing.T) {
broadcaster := NewChannelBroadcaster()
assert.NotNil(t,broadcaster)
assert.NotNil(t, broadcaster)
channel1 := broadcaster.NewSubscriber()
channel2 := broadcaster.NewSubscriber()
assert.NotNil(t,channel1)
assert.NotNil(t,channel2)
assert.NotNil(t, channel1)
assert.NotNil(t, channel2)
//Add a message to trigger
broadcaster.trigger <- 1
msg1 := <- channel1
msg2 := <- channel2
assert.Equal(t,1,msg1)
msg1 := <-channel1
msg2 := <-channel2
assert.Equal(t, 1, msg1)
//Check if all the subscribers received the same message
assert.Equal(t,msg2,msg1)
assert.Equal(t, msg2, msg1)
close(broadcaster.trigger)
}

2 changes: 1 addition & 1 deletion escrow/allowed_user_payment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func AllowedUserPaymentHandler() handler.PaymentHandler {
}
}

//clients should be oblivious to this handler
// clients should be oblivious to this handler
func (h *allowedUserPaymentHandler) Type() (typ string) {
return EscrowPaymentType
}
Expand Down
7 changes: 3 additions & 4 deletions escrow/income.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type IncomeData struct {
GrpcContext *handler.GrpcStreamContext
}

// IncomeValidator uses pricing information to check that call was payed
// IncomeValidator uses pricing information to check that call was paid
// correctly by channel sender. This interface can be implemented differently
// depending on pricing policy. For instance one can verify that call is payed
// depending on pricing policy. For instance one can verify that call is paid
// according to invoice. Each RPC method can have different price and so on. To
// implement this strategies additional information from gRPC context can be
// implement these strategies additional information from gRPC context can be
// required. In such case it should be added into handler.GrpcStreamContext.
type IncomeValidator interface {
// Validate returns nil if validation is successful or correct PaymentError
Expand All @@ -41,7 +41,6 @@ func NewIncomeValidator(pricing *pricing.PricingStrategy) (validator IncomeValid
}

func (validator *incomeValidator) Validate(data *IncomeData) (err error) {
//TO DO, the user request information from IncomeData needs to be passed here !!!!
price, err := validator.priceStrategy.GetPrice(data.GrpcContext)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions escrow/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"go.uber.org/zap"
)

// Lock is an aquired lock.
// Lock is an acquired lock.
type Lock interface {
// Unlock frees lock
Unlock() (err error)
}

// Locker is an interface to aquire lock
// Locker is an interface to acquire lock
type Locker interface {
// Lock aquires and returns lock. ok is false if lock cannot be aquired.
// Lock acquires and returns lock. ok is false if lock cannot be acquired.
Lock(name string) (lock Lock, ok bool, err error)
}

Expand Down
2 changes: 1 addition & 1 deletion escrow/payment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type paymentChannelPaymentHandler struct {
incomeValidator IncomeValidator
}

// NewPaymentHandler retuns new MultiPartyEscrow contract payment handler.
// NewPaymentHandler returns new MultiPartyEscrow contract payment handler.
func NewPaymentHandler(
service PaymentChannelService,
processor *blockchain.Processor,
Expand Down
2 changes: 1 addition & 1 deletion handler/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type Payment any

// Custom gRPC codes to return to the client
const (
// IncorrectNonce is returned to client when payment recieved contains
// IncorrectNonce is returned to client when payment received contains
// incorrect nonce value. Client may use PaymentChannelStateService to get
// latest channel state and correct nonce value.
IncorrectNonce codes.Code = 1000
Expand Down
2 changes: 1 addition & 1 deletion license_server/license_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type LicenseTransaction interface {
Rollback() error
}

//this is used to track the license Usage
// this is used to track the license Usage
type licenseUsageTrackerTransactionImpl struct {
channelId *big.Int
usage Usage
Expand Down
4 changes: 1 addition & 3 deletions metrics/request_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
)

//Request stats that will be captured
// Request stats that will be captured
type RequestStats struct {
Type string `json:"type"`
RegistryAddressKey string `json:"registry_address_key"`
Expand All @@ -26,8 +26,6 @@ type RequestStats struct {
ChannelId string `json:"channel_id"`
}



func (request *RequestStats) setDataFromContext(md metadata.MD) {
request.InputDataSize = strconv.FormatUint(GetSize(md), 10)

Expand Down
2 changes: 1 addition & 1 deletion metrics/request_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCreateRequestStat(t *testing.T) {
commonStat.ClientType = "snet-cli"
commonStat.UserDetails = "0x94d04332C4f5273feF69c4a52D24f42a3aF1F207"
commonStat.UserAgent = "python/cli"
commonStat.ChannelId = "2"
commonStat.ChannelId = "2"
request := createRequestStat(commonStat)
assert.Equal(t, request.RequestID, commonStat.ID)
assert.Equal(t, request.GroupID, daemonGroupId)
Expand Down
Loading

0 comments on commit 11a79fa

Please sign in to comment.