Fix waku tests & contact ens (#1802)
This commit is contained in:
parent
ae18729f59
commit
25d46c6d82
2
Makefile
2
Makefile
|
@ -244,7 +244,7 @@ test-unit: UNIT_TEST_PACKAGES = $(shell go list ./... | \
|
|||
grep -v /lib | \
|
||||
grep -v /transactions/fake )
|
||||
test-unit: ##@tests Run unit and integration tests
|
||||
go test -v -failfast $(UNIT_TEST_PACKAGES) $(gotest_extraflags)
|
||||
go test -v -failfast $(UNIT_TEST_PACKAGES) $(gotest_extraflags) && cd ./protocol && $(MAKE) test
|
||||
|
||||
test-unit-race: gotest_extraflags=-race
|
||||
test-unit-race: test-unit ##@tests Run unit and integration tests with -race flag
|
||||
|
|
|
@ -6,6 +6,14 @@ import (
|
|||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
type TransactionStatus uint64
|
||||
|
||||
const (
|
||||
TransactionStatusFailed = 0
|
||||
TransactionStatusSuccess = 1
|
||||
TransactionStatusPending = 2
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
to *types.Address
|
||||
from types.Address
|
||||
|
|
|
@ -13,7 +13,9 @@ replace github.com/status-im/status-go/waku => ../waku
|
|||
require (
|
||||
github.com/ethereum/go-ethereum v1.9.5
|
||||
github.com/mattn/go-pointer v0.0.0-20190911064623-a0a44394634f
|
||||
github.com/pborman/uuid v1.2.0
|
||||
github.com/status-im/doubleratchet v3.0.0+incompatible
|
||||
github.com/status-im/status-go/extkeys v1.0.0
|
||||
github.com/status-im/status-go/waku v1.0.0
|
||||
github.com/status-im/status-go/whisper/v6 v6.0.1 // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
|
|
|
@ -323,6 +323,7 @@ golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIo
|
|||
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE=
|
||||
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4=
|
||||
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
||||
|
|
|
@ -519,6 +519,11 @@ type ShhextConfig struct {
|
|||
// VerifyTransactionURL is the URL for verifying transactions.
|
||||
// IMPORTANT: It should always be mainnet unless used for testing
|
||||
VerifyTransactionURL string
|
||||
|
||||
// VerifyENSURL is the URL for verifying ens names.
|
||||
// IMPORTANT: It should always be mainnet unless used for testing
|
||||
VerifyENSURL string
|
||||
|
||||
VerifyTransactionChainID int64
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ type Contact struct {
|
|||
SystemTags []string `json:"systemTags"`
|
||||
|
||||
DeviceInfo []ContactDeviceInfo `json:"deviceInfo"`
|
||||
TributeToTalk string `json:"tributeToTalk"`
|
||||
TributeToTalk string `json:"tributeToTalk,omitEmpty"`
|
||||
}
|
||||
|
||||
func (c Contact) PublicKey() (*ecdsa.PublicKey, error) {
|
||||
|
|
|
@ -419,7 +419,7 @@ func (m *MessageHandler) HandleAcceptRequestAddressForTransaction(messageState *
|
|||
initialMessage.CommandParameters.CommandState = CommandStateRequestAddressForTransactionAccepted
|
||||
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(command.Id)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(messageState.CurrentMessageState.Contact.ID, command.Id)
|
||||
if err != nil && err != errRecordNotFound {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -678,6 +678,11 @@ func (m *Messenger) CreateGroupChatWithMembers(ctx context.Context, name string,
|
|||
|
||||
response.Chats = []*Chat{&chat}
|
||||
response.Messages = buildSystemMessages(chat.MembershipUpdates, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(&chat)
|
||||
}
|
||||
|
||||
|
@ -737,6 +742,11 @@ func (m *Messenger) RemoveMemberFromGroupChat(ctx context.Context, chatID string
|
|||
chat.updateChatFromProtocolGroup(group)
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages(chat.MembershipUpdates, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
||||
|
@ -796,6 +806,10 @@ func (m *Messenger) AddMembersToGroupChat(ctx context.Context, chatID string, me
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
@ -857,6 +871,10 @@ func (m *Messenger) AddAdminsToGroupChat(ctx context.Context, chatID string, mem
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
@ -920,6 +938,10 @@ func (m *Messenger) ConfirmJoiningGroup(ctx context.Context, chatID string) (*Me
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
@ -985,6 +1007,11 @@ func (m *Messenger) LeaveGroupChat(ctx context.Context, chatID string) (*Messeng
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
||||
|
@ -2042,6 +2069,7 @@ func (m *Messenger) VerifyENSNames(rpcEndpoint, contractAddress string, ensDetai
|
|||
contact.ENSVerifiedAt = details.VerifiedAt
|
||||
contact.Name = details.Name
|
||||
|
||||
m.allContacts[contact.ID] = contact
|
||||
contacts = append(contacts, contact)
|
||||
} else {
|
||||
m.logger.Warn("Failed to resolve ens name",
|
||||
|
@ -2254,7 +2282,7 @@ func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, mess
|
|||
message.OutgoingStatus = OutgoingStatusSending
|
||||
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(messageID)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(chatID, messageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2513,7 +2541,7 @@ func (m *Messenger) AcceptRequestTransaction(ctx context.Context, transactionHas
|
|||
message.OutgoingStatus = OutgoingStatusSending
|
||||
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(messageID)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(chatID, messageID)
|
||||
if err != nil && err != errRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2734,8 +2762,9 @@ func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(message.CommandParameters.ID) != 0 {
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(message.CommandParameters.ID)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(chatID, message.CommandParameters.ID)
|
||||
if err != nil && err != errRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2747,6 +2776,7 @@ func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.
|
|||
}
|
||||
message.Replace = previousMessage.ID
|
||||
}
|
||||
}
|
||||
|
||||
response.Messages = append(response.Messages, message)
|
||||
m.allChats[chat.ID] = chat
|
||||
|
|
|
@ -72,6 +72,10 @@ func (n *testNode) RemovePeer(_ string) error {
|
|||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (n *testNode) GetWaku(_ interface{}) (types.Waku, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (n *testNode) GetWhisper(_ interface{}) (types.Whisper, error) {
|
||||
return n.shh, nil
|
||||
}
|
||||
|
@ -1631,6 +1635,7 @@ func (s *MessengerSuite) TestSendEthTransaction() {
|
|||
s.Require().True(ok)
|
||||
client.messages = make(map[string]MockTransaction)
|
||||
client.messages[transactionHash] = MockTransaction{
|
||||
Status: coretypes.TransactionStatusSuccess,
|
||||
Message: coretypes.NewMessage(
|
||||
senderAddress,
|
||||
&receiverAddress,
|
||||
|
@ -1731,6 +1736,7 @@ func (s *MessengerSuite) TestSendTokenTransaction() {
|
|||
s.Require().True(ok)
|
||||
client.messages = make(map[string]MockTransaction)
|
||||
client.messages[transactionHash] = MockTransaction{
|
||||
Status: coretypes.TransactionStatusSuccess,
|
||||
Message: coretypes.NewMessage(
|
||||
senderAddress,
|
||||
&contractAddress,
|
||||
|
@ -2064,6 +2070,7 @@ func (s *MessengerSuite) TestRequestTransaction() {
|
|||
s.Require().True(ok)
|
||||
client.messages = make(map[string]MockTransaction)
|
||||
client.messages[transactionHash] = MockTransaction{
|
||||
Status: coretypes.TransactionStatusSuccess,
|
||||
Message: coretypes.NewMessage(
|
||||
senderAddress,
|
||||
&contractAddress,
|
||||
|
@ -2100,7 +2107,7 @@ func (s *MessengerSuite) TestRequestTransaction() {
|
|||
}
|
||||
|
||||
type MockTransaction struct {
|
||||
Pending bool
|
||||
Status coretypes.TransactionStatus
|
||||
Message coretypes.Message
|
||||
}
|
||||
|
||||
|
@ -2113,12 +2120,12 @@ type mockSendMessagesRequest struct {
|
|||
req types.MessagesRequest
|
||||
}
|
||||
|
||||
func (m MockEthClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, bool, error) {
|
||||
func (m MockEthClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, coretypes.TransactionStatus, error) {
|
||||
mockTransaction, ok := m.messages[hash.Hex()]
|
||||
if !ok {
|
||||
return coretypes.Message{}, false, nil
|
||||
return coretypes.Message{}, coretypes.TransactionStatusFailed, nil
|
||||
} else {
|
||||
return mockTransaction.Message, mockTransaction.Pending, nil
|
||||
return mockTransaction.Message, mockTransaction.Status, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ func (db sqlitePersistence) messageByID(tx *sql.Tx, id string) (*Message, error)
|
|||
}
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) MessageByCommandID(id string) (*Message, error) {
|
||||
func (db sqlitePersistence) MessageByCommandID(chatID, id string) (*Message, error) {
|
||||
|
||||
var message Message
|
||||
|
||||
|
@ -259,10 +259,13 @@ func (db sqlitePersistence) MessageByCommandID(id string) (*Message, error) {
|
|||
m1.source = c.id
|
||||
WHERE
|
||||
m1.command_id = ?
|
||||
AND
|
||||
m1.local_chat_id = ?
|
||||
ORDER BY m1.clock_value DESC
|
||||
LIMIT 1
|
||||
`, allFields),
|
||||
id,
|
||||
chatID,
|
||||
)
|
||||
err := db.tableUserMessagesLegacyScanAllFields(row, &message)
|
||||
switch err {
|
||||
|
|
|
@ -62,7 +62,7 @@ func NewTransactionValidator(addresses []types.Address, persistence *sqlitePersi
|
|||
}
|
||||
|
||||
type EthClient interface {
|
||||
TransactionByHash(context.Context, types.Hash) (coretypes.Message, bool, error)
|
||||
TransactionByHash(context.Context, types.Hash) (coretypes.Message, coretypes.TransactionStatus, error)
|
||||
}
|
||||
|
||||
func (t *TransactionValidator) verifyTransactionSignature(ctx context.Context, from *ecdsa.PublicKey, address types.Address, transactionHash string, signature []byte) error {
|
||||
|
@ -243,7 +243,8 @@ func (t *TransactionValidator) ValidateTransactions(ctx context.Context) ([]*Ver
|
|||
var validationResult *VerifyTransactionResponse
|
||||
t.logger.Debug("Validating transaction", zap.Any("transaction", transaction))
|
||||
if transaction.CommandID != "" {
|
||||
message, err := t.persistence.MessageByCommandID(transaction.CommandID)
|
||||
chatID := contactIDFromPublicKey(transaction.From)
|
||||
message, err := t.persistence.MessageByCommandID(chatID, transaction.CommandID)
|
||||
if err != nil {
|
||||
|
||||
t.logger.Error("error pulling message", zap.Error(err))
|
||||
|
@ -313,13 +314,17 @@ func (t *TransactionValidator) ValidateTransaction(ctx context.Context, paramete
|
|||
c, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
message, pending, err := t.client.TransactionByHash(c, types.HexToHash(hash))
|
||||
message, status, err := t.client.TransactionByHash(c, types.HexToHash(hash))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pending {
|
||||
switch status {
|
||||
case coretypes.TransactionStatusPending:
|
||||
t.logger.Debug("Transaction pending")
|
||||
return &VerifyTransactionResponse{Pending: true}, nil
|
||||
case coretypes.TransactionStatusFailed:
|
||||
|
||||
return invalidResponse, nil
|
||||
}
|
||||
|
||||
return t.validateTransaction(ctx, message, parameters, from)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"testing"
|
||||
|
||||
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"github.com/status-im/status-go/protocol/tt"
|
||||
|
||||
_ "github.com/mutecomm/go-sqlcipher"
|
||||
|
@ -20,6 +19,23 @@ import (
|
|||
"github.com/status-im/status-go/whisper/v6"
|
||||
)
|
||||
|
||||
type testKeysPersistence struct {
|
||||
keys map[string][]byte
|
||||
}
|
||||
|
||||
func newTestKeysPersistence() *testKeysPersistence {
|
||||
return &testKeysPersistence{keys: make(map[string][]byte)}
|
||||
}
|
||||
|
||||
func (s *testKeysPersistence) Add(chatID string, key []byte) error {
|
||||
s.keys[chatID] = key
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *testKeysPersistence) All() (map[string][]byte, error) {
|
||||
return s.keys, nil
|
||||
}
|
||||
|
||||
func TestFiltersManagerSuite(t *testing.T) {
|
||||
suite.Run(t, new(FiltersManagerSuite))
|
||||
}
|
||||
|
@ -72,12 +88,11 @@ func (s *FiltersManagerSuite) SetupTest() {
|
|||
s.manager = append(s.manager, testKey)
|
||||
}
|
||||
|
||||
db, err := sqlite.Open(s.dbPath, "filter-key")
|
||||
s.Require().NoError(err)
|
||||
keysPersistence := newTestKeysPersistence()
|
||||
|
||||
whisper := gethbridge.NewGethWhisperWrapper(whisper.New(nil))
|
||||
|
||||
s.chats, err = NewFiltersManager(db, whisper, s.manager[0].privateKey, s.logger)
|
||||
s.chats, err = NewFiltersManager(keysPersistence, whisper, s.manager[0].privateKey, s.logger)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
|
@ -101,7 +116,7 @@ func (s *FiltersManagerSuite) TestPartitionedTopicWithDiscoveryDisabled() {
|
|||
func (s *FiltersManagerSuite) assertRequiredFilters() {
|
||||
partitionedTopic := fmt.Sprintf("contact-discovery-%d", s.manager[0].partitionedTopic)
|
||||
personalDiscoveryTopic := fmt.Sprintf("contact-discovery-%s", s.manager[0].publicKeyString())
|
||||
contactCodeTopic := contactCodeTopic(&s.manager[0].privateKey.PublicKey)
|
||||
contactCodeTopic := ContactCodeTopic(&s.manager[0].privateKey.PublicKey)
|
||||
|
||||
personalDiscoveryFilter := s.chats.filters[personalDiscoveryTopic]
|
||||
s.Require().NotNil(personalDiscoveryFilter, "It adds the discovery filter")
|
||||
|
|
|
@ -33,6 +33,7 @@ type Transport interface {
|
|||
LoadFilters(filters []*Filter) ([]*Filter, error)
|
||||
RemoveFilters(filters []*Filter) error
|
||||
ResetFilters() error
|
||||
Filters() []*Filter
|
||||
ProcessNegotiatedSecret(secret types.NegotiatedSecret) (*Filter, error)
|
||||
RetrieveRawAll() (map[Filter][]*types.Message, error)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -31,7 +32,7 @@ func TestEnvelopesMonitorSuite(t *testing.T) {
|
|||
func (s *EnvelopesMonitorSuite) SetupTest() {
|
||||
s.monitor = NewEnvelopesMonitor(
|
||||
nil,
|
||||
EnvelopesMonitorConfig{
|
||||
transport.EnvelopesMonitorConfig{
|
||||
EnvelopeEventsHandler: nil,
|
||||
MaxAttempts: 0,
|
||||
MailserverConfirmationsEnabled: false,
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -31,7 +32,7 @@ func TestEnvelopesMonitorSuite(t *testing.T) {
|
|||
func (s *EnvelopesMonitorSuite) SetupTest() {
|
||||
s.monitor = NewEnvelopesMonitor(
|
||||
nil,
|
||||
EnvelopesMonitorConfig{
|
||||
transport.EnvelopesMonitorConfig{
|
||||
EnvelopeEventsHandler: nil,
|
||||
MaxAttempts: 0,
|
||||
MailserverConfirmationsEnabled: false,
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/db"
|
||||
"github.com/status-im/status-go/mailserver"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/shhext/mailservers"
|
||||
"github.com/status-im/status-go/whisper/v6"
|
||||
|
||||
|
@ -657,7 +656,7 @@ func (api *PublicAPI) SetInstallationMetadata(installationID string, data *multi
|
|||
|
||||
// VerifyENSNames takes a list of ensdetails and returns whether they match the public key specified
|
||||
func (api *PublicAPI) VerifyENSNames(details []enstypes.ENSDetails) (map[string]enstypes.ENSResponse, error) {
|
||||
return api.service.messenger.VerifyENSNames(params.MainnetEthereumNetworkURL, ensContractAddress, details)
|
||||
return api.service.messenger.VerifyENSNames(api.service.config.VerifyENSURL, ensContractAddress, details)
|
||||
}
|
||||
|
||||
type ApplicationMessagesResponse struct {
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/shhext/mailservers"
|
||||
"github.com/status-im/status-go/services/wallet"
|
||||
"github.com/status-im/status-go/signal"
|
||||
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
|
@ -194,25 +195,26 @@ type verifyTransactionClient struct {
|
|||
url string
|
||||
}
|
||||
|
||||
func (c *verifyTransactionClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, bool, error) {
|
||||
func (c *verifyTransactionClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, coretypes.TransactionStatus, error) {
|
||||
signer := gethtypes.NewEIP155Signer(c.chainID)
|
||||
client, err := ethclient.Dial(c.url)
|
||||
if err != nil {
|
||||
return coretypes.Message{}, false, err
|
||||
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
||||
}
|
||||
|
||||
transaction, pending, err := client.TransactionByHash(ctx, commongethtypes.BytesToHash(hash.Bytes()))
|
||||
if err != nil {
|
||||
return coretypes.Message{}, false, err
|
||||
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
||||
}
|
||||
|
||||
message, err := transaction.AsMessage(signer)
|
||||
if err != nil {
|
||||
return coretypes.Message{}, false, err
|
||||
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
||||
}
|
||||
from := types.BytesToAddress(message.From().Bytes())
|
||||
to := types.BytesToAddress(message.To().Bytes())
|
||||
|
||||
if pending {
|
||||
return coretypes.NewMessage(
|
||||
from,
|
||||
&to,
|
||||
|
@ -222,7 +224,37 @@ func (c *verifyTransactionClient) TransactionByHash(ctx context.Context, hash ty
|
|||
message.GasPrice(),
|
||||
message.Data(),
|
||||
message.CheckNonce(),
|
||||
), pending, nil
|
||||
), coretypes.TransactionStatusPending, nil
|
||||
}
|
||||
|
||||
receipt, err := client.TransactionReceipt(ctx, commongethtypes.BytesToHash(hash.Bytes()))
|
||||
if err != nil {
|
||||
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
||||
}
|
||||
|
||||
coremessage := coretypes.NewMessage(
|
||||
from,
|
||||
&to,
|
||||
message.Nonce(),
|
||||
message.Value(),
|
||||
message.Gas(),
|
||||
message.GasPrice(),
|
||||
message.Data(),
|
||||
message.CheckNonce(),
|
||||
)
|
||||
|
||||
// Token transfer, check the logs
|
||||
if len(coremessage.Data()) != 0 {
|
||||
if wallet.IsTokenTransfer(receipt.Logs) {
|
||||
return coremessage, coretypes.TransactionStatus(receipt.Status), nil
|
||||
} else {
|
||||
return coremessage, coretypes.TransactionStatusFailed, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return coremessage, coretypes.TransactionStatus(receipt.Status), nil
|
||||
|
||||
}
|
||||
|
||||
func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct{}) {
|
||||
|
|
|
@ -111,7 +111,7 @@ func (d *ETHTransferDownloader) getTransfersInBlock(ctx context.Context, blk *ty
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isTokenTransfer(receipt.Logs) {
|
||||
if IsTokenTransfer(receipt.Logs) {
|
||||
log.Debug("eth downloader found token transfer", "hash", tx.Hash())
|
||||
continue
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ func (d *ERC20TransfersDownloader) GetTransfersInRange(parent context.Context, f
|
|||
return transfers, nil
|
||||
}
|
||||
|
||||
func isTokenTransfer(logs []*types.Log) bool {
|
||||
func IsTokenTransfer(logs []*types.Log) bool {
|
||||
signature := crypto.Keccak256Hash([]byte(erc20TransferEventSignature))
|
||||
for _, l := range logs {
|
||||
if len(l.Topics) > 0 && l.Topics[0] == signature {
|
||||
|
|
|
@ -6,6 +6,14 @@ import (
|
|||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
type TransactionStatus uint64
|
||||
|
||||
const (
|
||||
TransactionStatusFailed = 0
|
||||
TransactionStatusSuccess = 1
|
||||
TransactionStatusPending = 2
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
to *types.Address
|
||||
from types.Address
|
||||
|
|
|
@ -54,7 +54,7 @@ type Contact struct {
|
|||
SystemTags []string `json:"systemTags"`
|
||||
|
||||
DeviceInfo []ContactDeviceInfo `json:"deviceInfo"`
|
||||
TributeToTalk string `json:"tributeToTalk"`
|
||||
TributeToTalk string `json:"tributeToTalk,omitEmpty"`
|
||||
}
|
||||
|
||||
func (c Contact) PublicKey() (*ecdsa.PublicKey, error) {
|
||||
|
|
|
@ -419,7 +419,7 @@ func (m *MessageHandler) HandleAcceptRequestAddressForTransaction(messageState *
|
|||
initialMessage.CommandParameters.CommandState = CommandStateRequestAddressForTransactionAccepted
|
||||
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(command.Id)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(messageState.CurrentMessageState.Contact.ID, command.Id)
|
||||
if err != nil && err != errRecordNotFound {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -678,6 +678,11 @@ func (m *Messenger) CreateGroupChatWithMembers(ctx context.Context, name string,
|
|||
|
||||
response.Chats = []*Chat{&chat}
|
||||
response.Messages = buildSystemMessages(chat.MembershipUpdates, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(&chat)
|
||||
}
|
||||
|
||||
|
@ -737,6 +742,11 @@ func (m *Messenger) RemoveMemberFromGroupChat(ctx context.Context, chatID string
|
|||
chat.updateChatFromProtocolGroup(group)
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages(chat.MembershipUpdates, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
||||
|
@ -796,6 +806,10 @@ func (m *Messenger) AddMembersToGroupChat(ctx context.Context, chatID string, me
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
@ -857,6 +871,10 @@ func (m *Messenger) AddAdminsToGroupChat(ctx context.Context, chatID string, mem
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
@ -920,6 +938,10 @@ func (m *Messenger) ConfirmJoiningGroup(ctx context.Context, chatID string) (*Me
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
@ -985,6 +1007,11 @@ func (m *Messenger) LeaveGroupChat(ctx context.Context, chatID string) (*Messeng
|
|||
|
||||
response.Chats = []*Chat{chat}
|
||||
response.Messages = buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations)
|
||||
err = m.persistence.SaveMessagesLegacy(response.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, m.saveChat(chat)
|
||||
}
|
||||
|
||||
|
@ -2042,6 +2069,7 @@ func (m *Messenger) VerifyENSNames(rpcEndpoint, contractAddress string, ensDetai
|
|||
contact.ENSVerifiedAt = details.VerifiedAt
|
||||
contact.Name = details.Name
|
||||
|
||||
m.allContacts[contact.ID] = contact
|
||||
contacts = append(contacts, contact)
|
||||
} else {
|
||||
m.logger.Warn("Failed to resolve ens name",
|
||||
|
@ -2254,7 +2282,7 @@ func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, mess
|
|||
message.OutgoingStatus = OutgoingStatusSending
|
||||
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(messageID)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(chatID, messageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2513,7 +2541,7 @@ func (m *Messenger) AcceptRequestTransaction(ctx context.Context, transactionHas
|
|||
message.OutgoingStatus = OutgoingStatusSending
|
||||
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(messageID)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(chatID, messageID)
|
||||
if err != nil && err != errRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2734,8 +2762,9 @@ func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(message.CommandParameters.ID) != 0 {
|
||||
// Hide previous message
|
||||
previousMessage, err := m.persistence.MessageByCommandID(message.CommandParameters.ID)
|
||||
previousMessage, err := m.persistence.MessageByCommandID(chatID, message.CommandParameters.ID)
|
||||
if err != nil && err != errRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2747,6 +2776,7 @@ func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.
|
|||
}
|
||||
message.Replace = previousMessage.ID
|
||||
}
|
||||
}
|
||||
|
||||
response.Messages = append(response.Messages, message)
|
||||
m.allChats[chat.ID] = chat
|
||||
|
|
|
@ -237,7 +237,7 @@ func (db sqlitePersistence) messageByID(tx *sql.Tx, id string) (*Message, error)
|
|||
}
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) MessageByCommandID(id string) (*Message, error) {
|
||||
func (db sqlitePersistence) MessageByCommandID(chatID, id string) (*Message, error) {
|
||||
|
||||
var message Message
|
||||
|
||||
|
@ -259,10 +259,13 @@ func (db sqlitePersistence) MessageByCommandID(id string) (*Message, error) {
|
|||
m1.source = c.id
|
||||
WHERE
|
||||
m1.command_id = ?
|
||||
AND
|
||||
m1.local_chat_id = ?
|
||||
ORDER BY m1.clock_value DESC
|
||||
LIMIT 1
|
||||
`, allFields),
|
||||
id,
|
||||
chatID,
|
||||
)
|
||||
err := db.tableUserMessagesLegacyScanAllFields(row, &message)
|
||||
switch err {
|
||||
|
|
|
@ -62,7 +62,7 @@ func NewTransactionValidator(addresses []types.Address, persistence *sqlitePersi
|
|||
}
|
||||
|
||||
type EthClient interface {
|
||||
TransactionByHash(context.Context, types.Hash) (coretypes.Message, bool, error)
|
||||
TransactionByHash(context.Context, types.Hash) (coretypes.Message, coretypes.TransactionStatus, error)
|
||||
}
|
||||
|
||||
func (t *TransactionValidator) verifyTransactionSignature(ctx context.Context, from *ecdsa.PublicKey, address types.Address, transactionHash string, signature []byte) error {
|
||||
|
@ -243,7 +243,8 @@ func (t *TransactionValidator) ValidateTransactions(ctx context.Context) ([]*Ver
|
|||
var validationResult *VerifyTransactionResponse
|
||||
t.logger.Debug("Validating transaction", zap.Any("transaction", transaction))
|
||||
if transaction.CommandID != "" {
|
||||
message, err := t.persistence.MessageByCommandID(transaction.CommandID)
|
||||
chatID := contactIDFromPublicKey(transaction.From)
|
||||
message, err := t.persistence.MessageByCommandID(chatID, transaction.CommandID)
|
||||
if err != nil {
|
||||
|
||||
t.logger.Error("error pulling message", zap.Error(err))
|
||||
|
@ -313,13 +314,17 @@ func (t *TransactionValidator) ValidateTransaction(ctx context.Context, paramete
|
|||
c, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
message, pending, err := t.client.TransactionByHash(c, types.HexToHash(hash))
|
||||
message, status, err := t.client.TransactionByHash(c, types.HexToHash(hash))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pending {
|
||||
switch status {
|
||||
case coretypes.TransactionStatusPending:
|
||||
t.logger.Debug("Transaction pending")
|
||||
return &VerifyTransactionResponse{Pending: true}, nil
|
||||
case coretypes.TransactionStatusFailed:
|
||||
|
||||
return invalidResponse, nil
|
||||
}
|
||||
|
||||
return t.validateTransaction(ctx, message, parameters, from)
|
||||
|
|
|
@ -33,6 +33,7 @@ type Transport interface {
|
|||
LoadFilters(filters []*Filter) ([]*Filter, error)
|
||||
RemoveFilters(filters []*Filter) error
|
||||
ResetFilters() error
|
||||
Filters() []*Filter
|
||||
ProcessNegotiatedSecret(secret types.NegotiatedSecret) (*Filter, error)
|
||||
RetrieveRawAll() (map[Filter][]*types.Message, error)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue