add ChatID to transaction commands (#2274)

This commit is contained in:
Bitgamma 2021-07-07 14:18:18 +03:00 committed by GitHub
parent 491e2a84c4
commit 58e39adf03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 31 deletions

View File

@ -1 +1 @@
0.80.6
0.81.0

View File

@ -3215,6 +3215,7 @@ func (m *Messenger) RequestTransaction(ctx context.Context, chatID, value, contr
Address: address,
Value: value,
Contract: contract,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {
@ -3287,6 +3288,7 @@ func (m *Messenger) RequestAddressForTransaction(ctx context.Context, chatID, fr
Clock: message.Clock,
Value: value,
Contract: contract,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {
@ -3384,6 +3386,7 @@ func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, mess
Clock: message.Clock,
Id: messageID,
Address: address,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {
@ -3461,8 +3464,9 @@ func (m *Messenger) DeclineRequestTransaction(ctx context.Context, messageID str
}
request := &protobuf.DeclineRequestTransaction{
Clock: message.Clock,
Id: messageID,
Clock: message.Clock,
Id: messageID,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {
@ -3539,8 +3543,9 @@ func (m *Messenger) DeclineRequestAddressForTransaction(ctx context.Context, mes
}
request := &protobuf.DeclineRequestAddressForTransaction{
Clock: message.Clock,
Id: messageID,
Clock: message.Clock,
Id: messageID,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {
@ -3634,6 +3639,7 @@ func (m *Messenger) AcceptRequestTransaction(ctx context.Context, transactionHas
Id: messageID,
TransactionHash: transactionHash,
Signature: signature,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {
@ -3707,6 +3713,7 @@ func (m *Messenger) SendTransaction(ctx context.Context, chatID, value, contract
Clock: message.Clock,
TransactionHash: transactionHash,
Signature: signature,
ChatId: chatID,
}
encodedMessage, err := proto.Marshal(request)
if err != nil {

View File

@ -689,10 +689,11 @@ func (m *Messenger) HandleRequestAddressForTransaction(messageState *ReceivedMes
}
message := &common.Message{
ChatMessage: protobuf.ChatMessage{
Clock: command.Clock,
Timestamp: messageState.CurrentMessageState.WhisperTimestamp,
Text: "Request address for transaction",
ChatId: contactIDFromPublicKey(&m.identity.PublicKey),
Clock: command.Clock,
Timestamp: messageState.CurrentMessageState.WhisperTimestamp,
Text: "Request address for transaction",
// ChatId is only used as-is for messages sent to oneself (i.e: mostly sync) so no need to check it here
ChatId: command.GetChatId(),
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND,
},
@ -713,10 +714,11 @@ func (m *Messenger) HandleRequestTransaction(messageState *ReceivedMessageState,
}
message := &common.Message{
ChatMessage: protobuf.ChatMessage{
Clock: command.Clock,
Timestamp: messageState.CurrentMessageState.WhisperTimestamp,
Text: "Request transaction",
ChatId: contactIDFromPublicKey(&m.identity.PublicKey),
Clock: command.Clock,
Timestamp: messageState.CurrentMessageState.WhisperTimestamp,
Text: "Request transaction",
// ChatId is only used for messages sent to oneself (i.e: mostly sync) so no need to check it here
ChatId: command.GetChatId(),
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND,
},
@ -762,6 +764,7 @@ func (m *Messenger) HandleAcceptRequestAddressForTransaction(messageState *Recei
initialMessage.CommandParameters.Address = command.Address
initialMessage.Seen = false
initialMessage.CommandParameters.CommandState = common.CommandStateRequestAddressForTransactionAccepted
initialMessage.ChatId = command.GetChatId()
// Hide previous message
previousMessage, err := m.persistence.MessageByCommandID(messageState.CurrentMessageState.Contact.ID, command.Id)
@ -831,6 +834,7 @@ func (m *Messenger) HandleDeclineRequestAddressForTransaction(messageState *Rece
oldMessage.Text = requestAddressForTransactionDeclinedMessage
oldMessage.Seen = false
oldMessage.CommandParameters.CommandState = common.CommandStateRequestAddressForTransactionDeclined
oldMessage.ChatId = command.GetChatId()
// Hide previous message
err = m.persistence.HideMessage(command.Id)
@ -872,6 +876,7 @@ func (m *Messenger) HandleDeclineRequestTransaction(messageState *ReceivedMessag
oldMessage.Text = transactionRequestDeclinedMessage
oldMessage.Seen = false
oldMessage.CommandParameters.CommandState = common.CommandStateRequestTransactionDeclined
oldMessage.ChatId = command.GetChatId()
// Hide previous message
err = m.persistence.HideMessage(command.Id)

View File

@ -1612,6 +1612,7 @@ func (s *MessengerSuite) TestDeclineRequestAddressForTransaction() {
_, err := theirMessenger.Start()
s.Require().NoError(err)
theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
myPkString := types.EncodeHex(crypto.FromECDSAPub(&s.m.identity.PublicKey))
chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey, s.m.transport)
err = s.m.SaveChat(chat)
@ -1655,6 +1656,7 @@ func (s *MessengerSuite) TestDeclineRequestAddressForTransaction() {
s.Require().Equal(value, receiverMessage.CommandParameters.Value)
s.Require().Equal(contract, receiverMessage.CommandParameters.Contract)
s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID)
s.Require().Equal(theirPkString, receiverMessage.ChatId)
s.Require().Equal(common.CommandStateRequestAddressForTransaction, receiverMessage.CommandParameters.CommandState)
// We decline the request
@ -1692,6 +1694,7 @@ func (s *MessengerSuite) TestDeclineRequestAddressForTransaction() {
s.Require().Equal(contract, receiverMessage.CommandParameters.Contract)
s.Require().Equal(common.CommandStateRequestAddressForTransactionDeclined, receiverMessage.CommandParameters.CommandState)
s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID)
s.Require().Equal(myPkString, receiverMessage.ChatId)
s.Require().Equal(initialCommandID, receiverMessage.Replace)
s.Require().NoError(theirMessenger.Shutdown())
}
@ -1911,6 +1914,7 @@ func (s *MessengerSuite) TestAcceptRequestAddressForTransaction() {
_, err := theirMessenger.Start()
s.Require().NoError(err)
theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
myPkString := types.EncodeHex(crypto.FromECDSAPub(&s.m.identity.PublicKey))
myAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey)
@ -1955,6 +1959,7 @@ func (s *MessengerSuite) TestAcceptRequestAddressForTransaction() {
s.Require().Equal(contract, receiverMessage.CommandParameters.Contract)
s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID)
s.Require().Equal(common.CommandStateRequestAddressForTransaction, receiverMessage.CommandParameters.CommandState)
s.Require().Equal(theirPkString, receiverMessage.ChatId)
// We accept the request
response, err = theirMessenger.AcceptRequestAddressForTransaction(context.Background(), receiverMessage.ID, "some-address")
@ -1994,6 +1999,7 @@ func (s *MessengerSuite) TestAcceptRequestAddressForTransaction() {
s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID)
s.Require().Equal("some-address", receiverMessage.CommandParameters.Address)
s.Require().Equal(initialCommandID, receiverMessage.Replace)
s.Require().Equal(myPkString, receiverMessage.ChatId)
s.Require().NoError(theirMessenger.Shutdown())
}

View File

@ -24,6 +24,7 @@ type RequestAddressForTransaction struct {
Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"`
Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"`
ChatId string `protobuf:"bytes,4,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -75,10 +76,18 @@ func (m *RequestAddressForTransaction) GetContract() string {
return ""
}
func (m *RequestAddressForTransaction) GetChatId() string {
if m != nil {
return m.ChatId
}
return ""
}
type AcceptRequestAddressForTransaction struct {
Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
ChatId string `protobuf:"bytes,4,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -130,9 +139,17 @@ func (m *AcceptRequestAddressForTransaction) GetAddress() string {
return ""
}
func (m *AcceptRequestAddressForTransaction) GetChatId() string {
if m != nil {
return m.ChatId
}
return ""
}
type DeclineRequestAddressForTransaction struct {
Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
ChatId string `protobuf:"bytes,3,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -177,9 +194,17 @@ func (m *DeclineRequestAddressForTransaction) GetId() string {
return ""
}
func (m *DeclineRequestAddressForTransaction) GetChatId() string {
if m != nil {
return m.ChatId
}
return ""
}
type DeclineRequestTransaction struct {
Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
ChatId string `protobuf:"bytes,3,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -224,11 +249,19 @@ func (m *DeclineRequestTransaction) GetId() string {
return ""
}
func (m *DeclineRequestTransaction) GetChatId() string {
if m != nil {
return m.ChatId
}
return ""
}
type RequestTransaction struct {
Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"`
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`
Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"`
ChatId string `protobuf:"bytes,5,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -287,11 +320,19 @@ func (m *RequestTransaction) GetContract() string {
return ""
}
func (m *RequestTransaction) GetChatId() string {
if m != nil {
return m.ChatId
}
return ""
}
type SendTransaction struct {
Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
TransactionHash string `protobuf:"bytes,3,opt,name=transaction_hash,json=transactionHash,proto3" json:"transaction_hash,omitempty"`
Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"`
ChatId string `protobuf:"bytes,5,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -350,6 +391,13 @@ func (m *SendTransaction) GetSignature() []byte {
return nil
}
func (m *SendTransaction) GetChatId() string {
if m != nil {
return m.ChatId
}
return ""
}
func init() {
proto.RegisterType((*RequestAddressForTransaction)(nil), "protobuf.RequestAddressForTransaction")
proto.RegisterType((*AcceptRequestAddressForTransaction)(nil), "protobuf.AcceptRequestAddressForTransaction")
@ -364,22 +412,24 @@ func init() {
}
var fileDescriptor_213c0bb044472049 = []byte{
// 257 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x4b, 0x03, 0x31,
0x10, 0x85, 0xd9, 0x6d, 0xd5, 0x76, 0x50, 0x2b, 0xc1, 0xc3, 0x2a, 0x3d, 0x94, 0x78, 0xa9, 0x17,
0x2f, 0xfe, 0x82, 0x05, 0x11, 0x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bf, 0x43, 0x5f,
0x8a, 0x29, 0x8c, 0xbd, 0x7e, 0x36, 0x18, 0x6a, 0xc7, 0xf1, 0x05, 0x87, 0x45, 0x67, 0x2c, 0xf6,
0xe3, 0x17, 0xbb, 0x7e, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x13, 0xdb, 0x87, 0x02, 0x7a, 0x02, 0x00,
0x00,
// 291 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0x3d, 0x4f, 0xfb, 0x30,
0x10, 0xc6, 0x95, 0x97, 0xbe, 0x9d, 0xfe, 0x7f, 0x8a, 0x2c, 0x24, 0x02, 0xea, 0x50, 0x85, 0xa5,
0x2c, 0x2c, 0x7c, 0x82, 0x4a, 0x08, 0xc1, 0x1a, 0x98, 0x58, 0xaa, 0xeb, 0xd9, 0x10, 0x8b, 0xd4,
0x2e, 0xb6, 0xc3, 0x86, 0xf8, 0x08, 0xcc, 0x7c, 0x5b, 0x54, 0x27, 0xb4, 0xc9, 0x10, 0x09, 0x50,
0xa7, 0xe8, 0xb9, 0xd3, 0xdd, 0xf3, 0xcb, 0x3d, 0x86, 0xff, 0xa4, 0x57, 0x2b, 0x54, 0xfc, 0x62,
0x6d, 0xb4, 0xd3, 0x6c, 0xe8, 0x3f, 0xcb, 0xf2, 0x31, 0x7d, 0x87, 0x49, 0x26, 0x5e, 0x4a, 0x61,
0xdd, 0x9c, 0x73, 0x23, 0xac, 0xbd, 0xd6, 0xe6, 0xde, 0xa0, 0xb2, 0x48, 0x4e, 0x6a, 0xc5, 0x8e,
0xa0, 0x47, 0x85, 0xa6, 0xe7, 0x24, 0x98, 0x06, 0xb3, 0x38, 0xab, 0xc4, 0xa6, 0xfa, 0x8a, 0x45,
0x29, 0x92, 0x70, 0x1a, 0xcc, 0x46, 0x59, 0x25, 0xd8, 0x29, 0x0c, 0x49, 0x2b, 0x67, 0x90, 0x5c,
0x12, 0xf9, 0xc6, 0x56, 0xb3, 0x63, 0x18, 0x50, 0x8e, 0x6e, 0x21, 0x79, 0x12, 0xfb, 0x56, 0x7f,
0x23, 0x6f, 0x79, 0xfa, 0x06, 0xe9, 0x9c, 0x48, 0xac, 0xdd, 0x1f, 0x30, 0x0e, 0x20, 0x94, 0xbc,
0x66, 0x08, 0x25, 0x67, 0x09, 0x0c, 0xb0, 0x1a, 0xaf, 0xfd, 0xbf, 0x65, 0xb7, 0x3d, 0x87, 0xb3,
0x2b, 0x41, 0x85, 0x54, 0x62, 0x0f, 0xfe, 0x0d, 0x97, 0xa8, 0xe5, 0xf2, 0x00, 0x27, 0x6d, 0x97,
0x3d, 0xee, 0xfe, 0x08, 0x80, 0xfd, 0x78, 0x6b, 0xe3, 0x42, 0x61, 0xfb, 0x42, 0xdb, 0x48, 0xa3,
0xae, 0x48, 0xe3, 0xee, 0x48, 0x7b, 0x2d, 0xa2, 0xcf, 0x00, 0xc6, 0x77, 0x42, 0xf1, 0xdf, 0xff,
0xe4, 0x39, 0x1c, 0xba, 0xdd, 0xd0, 0x22, 0x47, 0x9b, 0xd7, 0x3c, 0xe3, 0x46, 0xfd, 0x06, 0x6d,
0xce, 0x26, 0x30, 0xb2, 0xf2, 0x49, 0xa1, 0x2b, 0x8d, 0xf0, 0x68, 0xff, 0xb2, 0x5d, 0xa1, 0x93,
0x6d, 0xd9, 0xf7, 0x2f, 0xff, 0xf2, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x95, 0xdf, 0x2b, 0xe4, 0x11,
0x03, 0x00, 0x00,
}

View File

@ -6,22 +6,26 @@ message RequestAddressForTransaction {
uint64 clock = 1;
string value = 2;
string contract = 3;
string chat_id = 4;
}
message AcceptRequestAddressForTransaction {
uint64 clock = 1;
string id = 2;
string address = 3;
string chat_id = 4;
}
message DeclineRequestAddressForTransaction {
uint64 clock = 1;
string id = 2;
string chat_id = 3;
}
message DeclineRequestTransaction {
uint64 clock = 1;
string id = 2;
string chat_id = 3;
}
message RequestTransaction {
@ -29,6 +33,7 @@ message RequestTransaction {
string address = 2;
string value = 3;
string contract = 4;
string chat_id = 5;
}
message SendTransaction {
@ -36,4 +41,5 @@ message SendTransaction {
string id = 2;
string transaction_hash = 3;
bytes signature = 4;
string chat_id = 5;
}