Skip to content

Commit

Permalink
Merge pull request #291 from anandrgitnirman/testcasefailure
Browse files Browse the repository at this point in the history
#287, Add mpe_address to GetChannelState authentication
  • Loading branch information
raamb authored Jun 12, 2019
2 parents 148491b + 8fc2ab5 commit c1071b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion escrow/state_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/singnet/snet-daemon/authutils"
"github.com/singnet/snet-daemon/blockchain"
log "github.com/sirupsen/logrus"
"golang.org/x/net/context"
"math/big"
Expand All @@ -17,6 +19,7 @@ import (
type PaymentChannelStateService struct {
channelService PaymentChannelService
paymentStorage *PaymentStorage
mpeAddress func() (address common.Address)
}

// verifies whether storage channel nonce is equal to blockchain nonce or not
Expand All @@ -35,10 +38,11 @@ func (service *PaymentChannelStateService) StorageNonceMatchesWithBlockchainNonc
}

// NewPaymentChannelStateService returns new instance of PaymentChannelStateService
func NewPaymentChannelStateService(channelService PaymentChannelService, paymentStorage *PaymentStorage) *PaymentChannelStateService {
func NewPaymentChannelStateService(channelService PaymentChannelService, paymentStorage *PaymentStorage,metaData *blockchain.ServiceMetadata) *PaymentChannelStateService {
return &PaymentChannelStateService{
channelService: channelService,
paymentStorage: paymentStorage,
mpeAddress:func() common.Address { return metaData.GetMpeAddress() },
}
}

Expand All @@ -65,6 +69,7 @@ func (service *PaymentChannelStateService) GetChannelState(context context.Conte
// signature verification
message := bytes.Join([][]byte{
[]byte("__get_channel_state"),
service.mpeAddress().Bytes(),
bigIntToBytes(channelID),
abi.U256(big.NewInt(int64(request.CurrentBlock))),
}, nil)
Expand Down
2 changes: 2 additions & 0 deletions escrow/state_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ var stateServiceTest = func() stateServiceTestType {
}

paymentStorage := NewPaymentStorage(NewMemStorage())
verificationAddress:= common.HexToAddress("0xf25186b5081ff5ce73482ad761db0eb0d25abfbf")

return stateServiceTestType{
service: PaymentChannelStateService{
channelService: channelServiceMock,
paymentStorage: paymentStorage,
mpeAddress: func() common.Address {return verificationAddress},
},
senderAddress: senderAddress,
signerPrivateKey: signerPrivateKey,
Expand Down
2 changes: 1 addition & 1 deletion snetd/cmd/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (components *Components) PaymentChannelStateService() (service *escrow.Paym
components.paymentChannelStateService = escrow.NewPaymentChannelStateService(
components.PaymentChannelService(),
components.PaymentStorage(),
)
components.ServiceMetaData())

return components.paymentChannelStateService
}
Expand Down

0 comments on commit c1071b4

Please sign in to comment.