create staking transaction

pull/402/head
Minh Doan 6 years ago
parent e4fe327426
commit 86f145ff42
  1. 0
      api/proto/message/gen.sh
  2. 137
      api/proto/message/message.pb.go
  3. 12
      api/proto/message/message.proto
  4. 21
      api/service/staking/service.go
  5. 3
      node/contract.go

@ -28,6 +28,7 @@ const (
MessageType_BOOTNODE_NEWNODE MessageType = 2 MessageType_BOOTNODE_NEWNODE MessageType = 2
MessageType_NEWNODE_BEACON MessageType = 3 MessageType_NEWNODE_BEACON MessageType = 3
MessageType_BEACON_NEWNODE MessageType = 4 MessageType_BEACON_NEWNODE MessageType = 4
MessageType_NEWNODE_BEACON_STAKING MessageType = 5
) )
var MessageType_name = map[int32]string{ var MessageType_name = map[int32]string{
@ -36,6 +37,7 @@ var MessageType_name = map[int32]string{
2: "BOOTNODE_NEWNODE", 2: "BOOTNODE_NEWNODE",
3: "NEWNODE_BEACON", 3: "NEWNODE_BEACON",
4: "BEACON_NEWNODE", 4: "BEACON_NEWNODE",
5: "NEWNODE_BEACON_STAKING",
} }
var MessageType_value = map[string]int32{ var MessageType_value = map[string]int32{
@ -44,6 +46,7 @@ var MessageType_value = map[string]int32{
"BOOTNODE_NEWNODE": 2, "BOOTNODE_NEWNODE": 2,
"NEWNODE_BEACON": 3, "NEWNODE_BEACON": 3,
"BEACON_NEWNODE": 4, "BEACON_NEWNODE": 4,
"NEWNODE_BEACON_STAKING": 5,
} }
func (x MessageType) String() string { func (x MessageType) String() string {
@ -61,9 +64,9 @@ func (MessageType) EnumDescriptor() ([]byte, []int) {
// The request field will be either one of the structure corresponding to the MessageType type. // The request field will be either one of the structure corresponding to the MessageType type.
type Message struct { type Message struct {
Type MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=message.MessageType" json:"type,omitempty"` Type MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=message.MessageType" json:"type,omitempty"`
Signature string `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"`
// Types that are valid to be assigned to Request: // Types that are valid to be assigned to Request:
// *Message_NewnodeBootnodeRequest // *Message_Staking
// *Message_BootnodeNewnodeRequest
Request isMessage_Request `protobuf_oneof:"request"` Request isMessage_Request `protobuf_oneof:"request"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
@ -102,21 +105,22 @@ func (m *Message) GetType() MessageType {
return MessageType_UNKNOWN return MessageType_UNKNOWN
} }
type isMessage_Request interface { func (m *Message) GetSignature() string {
isMessage_Request() if m != nil {
return m.Signature
} }
return ""
type Message_NewnodeBootnodeRequest struct {
NewnodeBootnodeRequest *NewNodeBootNodeRequest `protobuf:"bytes,2,opt,name=newnode_bootnode_request,json=newnodeBootnodeRequest,proto3,oneof"`
} }
type Message_BootnodeNewnodeRequest struct { type isMessage_Request interface {
BootnodeNewnodeRequest *BootNodeNewNodeRequest `protobuf:"bytes,3,opt,name=bootnode_newnode_request,json=bootnodeNewnodeRequest,proto3,oneof"` isMessage_Request()
} }
func (*Message_NewnodeBootnodeRequest) isMessage_Request() {} type Message_Staking struct {
Staking *StakingRequest `protobuf:"bytes,3,opt,name=staking,proto3,oneof"`
}
func (*Message_BootnodeNewnodeRequest) isMessage_Request() {} func (*Message_Staking) isMessage_Request() {}
func (m *Message) GetRequest() isMessage_Request { func (m *Message) GetRequest() isMessage_Request {
if m != nil { if m != nil {
@ -125,16 +129,9 @@ func (m *Message) GetRequest() isMessage_Request {
return nil return nil
} }
func (m *Message) GetNewnodeBootnodeRequest() *NewNodeBootNodeRequest { func (m *Message) GetStaking() *StakingRequest {
if x, ok := m.GetRequest().(*Message_NewnodeBootnodeRequest); ok { if x, ok := m.GetRequest().(*Message_Staking); ok {
return x.NewnodeBootnodeRequest return x.Staking
}
return nil
}
func (m *Message) GetBootnodeNewnodeRequest() *BootNodeNewNodeRequest {
if x, ok := m.GetRequest().(*Message_BootnodeNewnodeRequest); ok {
return x.BootnodeNewnodeRequest
} }
return nil return nil
} }
@ -142,8 +139,7 @@ func (m *Message) GetBootnodeNewnodeRequest() *BootNodeNewNodeRequest {
// XXX_OneofWrappers is for the internal use of the proto package. // XXX_OneofWrappers is for the internal use of the proto package.
func (*Message) XXX_OneofWrappers() []interface{} { func (*Message) XXX_OneofWrappers() []interface{} {
return []interface{}{ return []interface{}{
(*Message_NewnodeBootnodeRequest)(nil), (*Message_Staking)(nil),
(*Message_BootnodeNewnodeRequest)(nil),
} }
} }
@ -211,31 +207,92 @@ func (m *BootNodeNewNodeRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_BootNodeNewNodeRequest proto.InternalMessageInfo var xxx_messageInfo_BootNodeNewNodeRequest proto.InternalMessageInfo
// Staking Request from new node to beacon node.
type StakingRequest struct {
Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
Amount int64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"`
PublicKey string `protobuf:"bytes,4,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *StakingRequest) Reset() { *m = StakingRequest{} }
func (m *StakingRequest) String() string { return proto.CompactTextString(m) }
func (*StakingRequest) ProtoMessage() {}
func (*StakingRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_33c57e4bae7b9afd, []int{3}
}
func (m *StakingRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_StakingRequest.Unmarshal(m, b)
}
func (m *StakingRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_StakingRequest.Marshal(b, m, deterministic)
}
func (m *StakingRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_StakingRequest.Merge(m, src)
}
func (m *StakingRequest) XXX_Size() int {
return xxx_messageInfo_StakingRequest.Size(m)
}
func (m *StakingRequest) XXX_DiscardUnknown() {
xxx_messageInfo_StakingRequest.DiscardUnknown(m)
}
var xxx_messageInfo_StakingRequest proto.InternalMessageInfo
func (m *StakingRequest) GetAddress() string {
if m != nil {
return m.Address
}
return ""
}
func (m *StakingRequest) GetAmount() int64 {
if m != nil {
return m.Amount
}
return 0
}
func (m *StakingRequest) GetPublicKey() string {
if m != nil {
return m.PublicKey
}
return ""
}
func init() { func init() {
proto.RegisterEnum("message.MessageType", MessageType_name, MessageType_value) proto.RegisterEnum("message.MessageType", MessageType_name, MessageType_value)
proto.RegisterType((*Message)(nil), "message.Message") proto.RegisterType((*Message)(nil), "message.Message")
proto.RegisterType((*NewNodeBootNodeRequest)(nil), "message.NewNodeBootNodeRequest") proto.RegisterType((*NewNodeBootNodeRequest)(nil), "message.NewNodeBootNodeRequest")
proto.RegisterType((*BootNodeNewNodeRequest)(nil), "message.BootNodeNewNodeRequest") proto.RegisterType((*BootNodeNewNodeRequest)(nil), "message.BootNodeNewNodeRequest")
proto.RegisterType((*StakingRequest)(nil), "message.StakingRequest")
} }
func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) } func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) }
var fileDescriptor_33c57e4bae7b9afd = []byte{ var fileDescriptor_33c57e4bae7b9afd = []byte{
// 253 bytes of a gzipped FileDescriptorProto // 307 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x4b, 0xc3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0x51, 0x6b, 0xc2, 0x30,
0x10, 0x85, 0xbb, 0x6d, 0x31, 0x38, 0xc1, 0xb2, 0x2c, 0xa5, 0xe4, 0x66, 0xe9, 0x29, 0x78, 0xe8, 0x14, 0x85, 0x8d, 0x3a, 0x4b, 0xaf, 0x4c, 0xca, 0x45, 0x5c, 0x19, 0x1b, 0x88, 0x4f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x06, 0x66, 0x7d, 0x36, 0xd6, 0x9f, 0xbb, 0x8f, 0x68, 0x4f, 0xb9, 0xdf, 0x34, 0x6b, 0x19, 0x32, 0xa7, 0xfc, 0xe1, 0x87,
0x7f, 0x78, 0xb4, 0xa8, 0x27, 0xbe, 0xd7, 0xe9, 0x3e, 0x37, 0xdd, 0x5f, 0xb5, 0xdf, 0x75, 0xff, 0x41, 0xfb, 0xdf, 0x55, 0x60, 0x1b, 0x9c, 0x77, 0x3e, 0xe7, 0xe1, 0x8a, 0x7b, 0x35, 0xec, 0x82,
0x17, 0x00, 0x00, 0xff, 0xff, 0x37, 0x30, 0xd0, 0xfb, 0xbf, 0x01, 0x00, 0x00, 0xc7, 0x67, 0x2b, 0x1e, 0x3e, 0xcd, 0xa2, 0x69, 0x18, 0x2e, 0x0b, 0xe1, 0xb1, 0x82, 0x5a, 0x17,
0x55, 0xb1, 0x57, 0x47, 0x84, 0xce, 0xa9, 0x3b, 0x9b, 0x3c, 0x86, 0xdc, 0x6b, 0x14, 0xcc, 0xe8,
0x53, 0xaf, 0x89, 0xb7, 0xd0, 0xbb, 0xec, 0x45, 0x8b, 0xe5, 0x64, 0xfe, 0xca, 0x9f, 0xbd, 0xab,
0x75, 0xab, 0x7c, 0xc7, 0xf1, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x02, 0x35, 0x6a, 0x87, 0xd8,
0x01, 0x00, 0x00,
} }

@ -7,6 +7,7 @@ enum MessageType {
BOOTNODE_NEWNODE = 2; BOOTNODE_NEWNODE = 2;
NEWNODE_BEACON = 3; NEWNODE_BEACON = 3;
BEACON_NEWNODE = 4; BEACON_NEWNODE = 4;
NEWNODE_BEACON_STAKING = 5;
} }
// This is universal message for all communication protocols. // This is universal message for all communication protocols.
@ -16,9 +17,9 @@ enum MessageType {
// The request field will be either one of the structure corresponding to the MessageType type. // The request field will be either one of the structure corresponding to the MessageType type.
message Message { message Message {
MessageType type = 1; MessageType type = 1;
string signature = 2;
oneof request { oneof request {
NewNodeBootNodeRequest newnode_bootnode_request = 2; StakingRequest staking = 3;
BootNodeNewNodeRequest bootnode_newnode_request = 3;
} }
} }
@ -30,4 +31,9 @@ message NewNodeBootNodeRequest {
message BootNodeNewNodeRequest { message BootNodeNewNodeRequest {
} }
// TODO(minhdoan): refactor and introduce consensus message as one of possible Message.request. // Staking Request from new node to beacon node.
message StakingRequest {
string address = 1;
int64 amount = 2;
string public_key = 4;
}

@ -2,7 +2,9 @@ package staking
import ( import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/internal/utils/contract"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
) )
@ -54,6 +56,25 @@ func (s *Service) Run() {
// DoService does staking. // DoService does staking.
func (s *Service) DoService(peer *p2p.Peer) { func (s *Service) DoService(peer *p2p.Peer) {
utils.GetLogInstance().Info("Staking with Peer") utils.GetLogInstance().Info("Staking with Peer")
// TODO(minhdoan): How to use the p2p or pubsub to send Staking Message to beacon chain.
// See below of how to create a staking message.
}
func (s *Service) createStakingMessage() *message.Message {
// TODO(minhdoan): Add signature and public key.
// To add public we need to assign a fake account to new node initially.
return &message.Message{
Type: message.MessageType_NEWNODE_BEACON_STAKING,
Signature: "",
Request: &message.Message_Staking{
Staking: &message.StakingRequest{
Address: contract.FakeAccounts[0].Address,
Amount: 1000,
PublicKey: "",
},
},
}
} }
// StopService stops staking service. // StopService stops staking service.

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils/contract"
) )
const ( const (
@ -75,7 +76,7 @@ func (node *Node) createSendingMoneyTransaction(walletAddress common.Address) co
// DepositToFakeAccounts invokes the faucet contract to give the walletAddress initial money // DepositToFakeAccounts invokes the faucet contract to give the walletAddress initial money
func (node *Node) DepositToFakeAccounts() { func (node *Node) DepositToFakeAccounts() {
for _, deployAccount := range FakeAccounts { for _, deployAccount := range contract.FakeAccounts {
address := common.HexToAddress(deployAccount.Address) address := common.HexToAddress(deployAccount.Address)
node.createSendingMoneyTransaction(address) node.createSendingMoneyTransaction(address)
} }

Loading…
Cancel
Save