Merge pull request #402 from harmony-one/contract1

create staking transaction
pull/406/head
alajko 6 years ago committed by GitHub
commit 2886adebc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 0
      api/proto/message/gen.sh
  2. 139
      api/proto/message/message.pb.go
  3. 10
      api/proto/message/message.proto
  4. 18
      api/service/staking/service.go
  5. 2012
      internal/utils/contract/constants.go
  6. 32
      node/constants.go
  7. 84
      node/contract.go
  8. 59
      node/node.go

@ -23,11 +23,12 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type MessageType int32
const (
MessageType_UNKNOWN MessageType = 0
MessageType_NEWNODE_BOOTNODE MessageType = 1
MessageType_BOOTNODE_NEWNODE MessageType = 2
MessageType_NEWNODE_BEACON MessageType = 3
MessageType_BEACON_NEWNODE MessageType = 4
MessageType_UNKNOWN MessageType = 0
MessageType_NEWNODE_BOOTNODE MessageType = 1
MessageType_BOOTNODE_NEWNODE MessageType = 2
MessageType_NEWNODE_BEACON MessageType = 3
MessageType_BEACON_NEWNODE MessageType = 4
MessageType_NEWNODE_BEACON_STAKING MessageType = 5
)
var MessageType_name = map[int32]string{
@ -36,14 +37,16 @@ var MessageType_name = map[int32]string{
2: "BOOTNODE_NEWNODE",
3: "NEWNODE_BEACON",
4: "BEACON_NEWNODE",
5: "NEWNODE_BEACON_STAKING",
}
var MessageType_value = map[string]int32{
"UNKNOWN": 0,
"NEWNODE_BOOTNODE": 1,
"BOOTNODE_NEWNODE": 2,
"NEWNODE_BEACON": 3,
"BEACON_NEWNODE": 4,
"UNKNOWN": 0,
"NEWNODE_BOOTNODE": 1,
"BOOTNODE_NEWNODE": 2,
"NEWNODE_BEACON": 3,
"BEACON_NEWNODE": 4,
"NEWNODE_BEACON_STAKING": 5,
}
func (x MessageType) String() string {
@ -62,8 +65,7 @@ func (MessageType) EnumDescriptor() ([]byte, []int) {
type Message struct {
Type MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=message.MessageType" json:"type,omitempty"`
// Types that are valid to be assigned to Request:
// *Message_NewnodeBootnodeRequest
// *Message_BootnodeNewnodeRequest
// *Message_Staking
Request isMessage_Request `protobuf_oneof:"request"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
@ -106,17 +108,11 @@ type isMessage_Request interface {
isMessage_Request()
}
type Message_NewnodeBootnodeRequest struct {
NewnodeBootnodeRequest *NewNodeBootNodeRequest `protobuf:"bytes,2,opt,name=newnode_bootnode_request,json=newnodeBootnodeRequest,proto3,oneof"`
type Message_Staking struct {
Staking *StakingRequest `protobuf:"bytes,3,opt,name=staking,proto3,oneof"`
}
type Message_BootnodeNewnodeRequest struct {
BootnodeNewnodeRequest *BootNodeNewNodeRequest `protobuf:"bytes,3,opt,name=bootnode_newnode_request,json=bootnodeNewnodeRequest,proto3,oneof"`
}
func (*Message_NewnodeBootnodeRequest) isMessage_Request() {}
func (*Message_BootnodeNewnodeRequest) isMessage_Request() {}
func (*Message_Staking) isMessage_Request() {}
func (m *Message) GetRequest() isMessage_Request {
if m != nil {
@ -125,16 +121,9 @@ func (m *Message) GetRequest() isMessage_Request {
return nil
}
func (m *Message) GetNewnodeBootnodeRequest() *NewNodeBootNodeRequest {
if x, ok := m.GetRequest().(*Message_NewnodeBootnodeRequest); ok {
return x.NewnodeBootnodeRequest
}
return nil
}
func (m *Message) GetBootnodeNewnodeRequest() *BootNodeNewNodeRequest {
if x, ok := m.GetRequest().(*Message_BootnodeNewnodeRequest); ok {
return x.BootnodeNewnodeRequest
func (m *Message) GetStaking() *StakingRequest {
if x, ok := m.GetRequest().(*Message_Staking); ok {
return x.Staking
}
return nil
}
@ -142,8 +131,7 @@ func (m *Message) GetBootnodeNewnodeRequest() *BootNodeNewNodeRequest {
// XXX_OneofWrappers is for the internal use of the proto package.
func (*Message) XXX_OneofWrappers() []interface{} {
return []interface{}{
(*Message_NewnodeBootnodeRequest)(nil),
(*Message_BootnodeNewnodeRequest)(nil),
(*Message_Staking)(nil),
}
}
@ -211,31 +199,82 @@ func (m *BootNodeNewNodeRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_BootNodeNewNodeRequest proto.InternalMessageInfo
// Staking Request from new node to beacon node.
type StakingRequest struct {
Transaction []byte `protobuf:"bytes,1,opt,name=transaction,proto3" json:"transaction,omitempty"`
NodeId string `protobuf:"bytes,2,opt,name=node_id,json=nodeId,proto3" json:"node_id,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) GetTransaction() []byte {
if m != nil {
return m.Transaction
}
return nil
}
func (m *StakingRequest) GetNodeId() string {
if m != nil {
return m.NodeId
}
return ""
}
func init() {
proto.RegisterEnum("message.MessageType", MessageType_name, MessageType_value)
proto.RegisterType((*Message)(nil), "message.Message")
proto.RegisterType((*NewNodeBootNodeRequest)(nil), "message.NewNodeBootNodeRequest")
proto.RegisterType((*BootNodeNewNodeRequest)(nil), "message.BootNodeNewNodeRequest")
proto.RegisterType((*StakingRequest)(nil), "message.StakingRequest")
}
func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) }
var fileDescriptor_33c57e4bae7b9afd = []byte{
// 253 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x4b, 0xc3, 0x40,
0x10, 0x85, 0xbb, 0x6d, 0x31, 0x38, 0xc1, 0xb2, 0x2c, 0xa5, 0xe4, 0x66, 0xe9, 0x29, 0x78, 0xe8,
0xa1, 0xfe, 0x02, 0xa3, 0x01, 0x41, 0x9c, 0x85, 0x50, 0xe9, 0xc1, 0x43, 0xb0, 0x74, 0xf0, 0x64,
0x26, 0x36, 0x2b, 0xa5, 0xff, 0xdc, 0xa3, 0x6c, 0x32, 0x1b, 0x8a, 0xe4, 0xb4, 0x6f, 0xe6, 0xbd,
0xf9, 0x66, 0xd9, 0x85, 0x9b, 0x2f, 0x6a, 0x9a, 0x8f, 0x4f, 0x5a, 0xd7, 0x47, 0x76, 0x6c, 0x22,
0x29, 0x57, 0xbf, 0x0a, 0xa2, 0xd7, 0x4e, 0x9b, 0x14, 0xa6, 0xee, 0x5c, 0x53, 0xa2, 0x96, 0x2a,
0x9d, 0x6d, 0xe6, 0xeb, 0x30, 0x22, 0xfe, 0xf6, 0x5c, 0x53, 0xd1, 0x26, 0xcc, 0x3b, 0x24, 0x15,
0x9d, 0x2a, 0x3e, 0x50, 0xb9, 0x67, 0x76, 0xad, 0x38, 0xd2, 0xf7, 0x0f, 0x35, 0x2e, 0x19, 0x2f,
0x55, 0x1a, 0x6f, 0x6e, 0xfb, 0x69, 0xa4, 0x13, 0xf2, 0x81, 0x32, 0x66, 0xe7, 0xcf, 0xa2, 0x8b,
0x3d, 0x8f, 0x8a, 0x85, 0x20, 0x32, 0x21, 0x88, 0xe3, 0xe1, 0x3d, 0x34, 0x6c, 0x09, 0xf0, 0xc9,
0x3f, 0x78, 0xa0, 0xca, 0x92, 0x0b, 0x78, 0x40, 0x60, 0x47, 0x10, 0x27, 0xbb, 0x86, 0x48, 0x58,
0xab, 0x04, 0x16, 0xc3, 0x77, 0xf3, 0xce, 0x30, 0xf8, 0xae, 0x82, 0xf8, 0xe2, 0x35, 0x4c, 0x0c,
0xd1, 0x1b, 0xbe, 0xa0, 0xdd, 0xa1, 0x1e, 0x99, 0x39, 0x68, 0xcc, 0x77, 0x68, 0x9f, 0xf2, 0x32,
0xb3, 0x76, 0xeb, 0x85, 0x56, 0xbe, 0x1b, 0xaa, 0x52, 0x6c, 0x3d, 0x36, 0x06, 0x66, 0x7d, 0x36,
0x7f, 0x78, 0xb4, 0xa8, 0x27, 0xbe, 0xd7, 0xe9, 0x3e, 0x37, 0xdd, 0x5f, 0xb5, 0xdf, 0x75, 0xff,
0x17, 0x00, 0x00, 0xff, 0xff, 0x37, 0x30, 0xd0, 0xfb, 0xbf, 0x01, 0x00, 0x00,
// 276 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0x4f, 0x6b, 0xc2, 0x30,
0x18, 0xc6, 0x8d, 0x3a, 0x83, 0x6f, 0xb7, 0x12, 0x82, 0x68, 0xd9, 0xa9, 0x78, 0x2a, 0x3b, 0x78,
0xd0, 0x4f, 0x60, 0xb7, 0xb2, 0x49, 0x59, 0x0a, 0xb1, 0xc3, 0x63, 0xe9, 0xd6, 0x20, 0x65, 0xac,
0xe9, 0x9a, 0x8c, 0xe1, 0x57, 0xd8, 0xa7, 0x1e, 0xfd, 0x93, 0xaa, 0xa7, 0xbc, 0xcf, 0xef, 0xf9,
0x25, 0x24, 0x04, 0xee, 0xbe, 0x84, 0x52, 0xe9, 0x51, 0xac, 0xca, 0x4a, 0x6a, 0x49, 0x71, 0x17,
0x97, 0x0a, 0xf0, 0x6b, 0x3b, 0x52, 0x0f, 0xc6, 0xfa, 0x54, 0x0a, 0x07, 0xb9, 0xc8, 0xb3, 0xd7,
0xb3,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ageType {
BOOTNODE_NEWNODE = 2;
NEWNODE_BEACON = 3;
BEACON_NEWNODE = 4;
NEWNODE_BEACON_STAKING = 5;
}
// This is universal message for all communication protocols.
@ -17,8 +18,7 @@ enum MessageType {
message Message {
MessageType type = 1;
oneof request {
NewNodeBootNodeRequest newnode_bootnode_request = 2;
BootNodeNewNodeRequest bootnode_newnode_request = 3;
StakingRequest staking = 3;
}
}
@ -30,4 +30,8 @@ message NewNodeBootNodeRequest {
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 {
bytes transaction = 1;
string node_id = 2;
}

@ -2,6 +2,7 @@ package staking
import (
"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/p2p"
)
@ -54,6 +55,23 @@ func (s *Service) Run() {
// DoService does staking.
func (s *Service) DoService(peer *p2p.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,
Request: &message.Message_Staking{
Staking: &message.StakingRequest{
Transaction: []byte{},
NodeId: "",
},
},
}
}
// StopService stops staking service.

File diff suppressed because it is too large Load Diff

@ -1,32 +0,0 @@
package node
// DeployAccount is the accounts used for development.
type DeployAccount struct {
Address string
Private string
Public string
}
// FakeAccounts is the accounts only used for development purpose.
var FakeAccounts = [...]DeployAccount{
{Address: "0xAAde00D97E9b2AAa19d2710b76d6413f993D9745", Private: "c6f4ab50857a394ed31297f9d41ace1816d2f566b3ef36639708d8799d98ce61", Public: "0xAAde00D97E9b2AAa19d2710b76d6413f993D9745"},
{Address: "0x3c44143624e0872D4e32Db1CE20Af2EbFe09F880", Private: "b9162457b06a474bdf00ba3107f830f5cccb1a6d316add395b80d3d36ddf84d4", Public: "0x3c44143624e0872D4e32Db1CE20Af2EbFe09F880"},
{Address: "0x8B7f5BA93996FFC10774b9F523c804918fb37635", Private: "d35ce93f89fe8d5dd76ed8cdb252ac143b53169add2b84a76e4780d705438f8e", Public: "0x8B7f5BA93996FFC10774b9F523c804918fb37635"},
{Address: "0x1973F2cDE703889Ba918e8864f040cD756DA710B", Private: "b8cf4ed5ba0b77a43b866524498b2f09ecdbfd036305d768292947e56bccceb7", Public: "0x1973F2cDE703889Ba918e8864f040cD756DA710B"},
{Address: "0xc41497315f5605Efc697Eb84C5b27980762556eD", Private: "8347df49470d61958c058e9d4d57e7915d6438b9c3a20444340e02c51a5ed2b4", Public: "0xc41497315f5605Efc697Eb84C5b27980762556eD"},
{Address: "0x32Ee9017f7b7dd05399Fb14525e1e56690894fB1", Private: "723927de4bb8a02deb8404cfda308e08e2cbc91f6de920cf0cb79c1232dde23f", Public: "0x32Ee9017f7b7dd05399Fb14525e1e56690894fB1"},
{Address: "0xe5C98A43f42E9fB1b290FBCBCEE6D31BCE433c6E", Private: "37b3db0c95d7d98166428a3dcdcbe3bb1e13d39aa08646f11bbb5accf4a546ee", Public: "0xe5C98A43f42E9fB1b290FBCBCEE6D31BCE433c6E"},
{Address: "0xBE4b41dc86A443Da147DA5a7a30D188EA8A45E58", Private: "3c1b4f6520b070d271c2de7d342d0eb664be82d2744307a64273049ff2354ee5", Public: "0xBE4b41dc86A443Da147DA5a7a30D188EA8A45E58"},
{Address: "0x2E0EF2E3e9f4F314b4cc54Efc1ea4cCc157E5749", Private: "88cc2c68a2f543ae2d0d2b363a03633fd5878a42f5e35049e773c29ec1ed4cd4", Public: "0x2E0EF2E3e9f4F314b4cc54Efc1ea4cCc157E5749"},
{Address: "0x01e58d72695197Fc35d24acfD909E390578cd962", Private: "4a9679c8b12bc48a442e75cd25bea47fb0c8b1cec56da65e145a642ffe8aa396", Public: "0x01e58d72695197Fc35d24acfD909E390578cd962"},
{Address: "0x35F5991124dF32E32552B59562EF46a5074cB5A3", Private: "61228f8938836278b99e3c37c9254fc23aa32c990287e466630d8b30c03627f4", Public: "0x35F5991124dF32E32552B59562EF46a5074cB5A3"},
{Address: "0xA832d248267af5e9B2eE78a8668EBb04AeA99613", Private: "8cd88a9cf78c2b685e793dece6f0171292cf72cbbfea831151d2b39935cb1532", Public: "0xA832d248267af5e9B2eE78a8668EBb04AeA99613"},
{Address: "0x11E88086EAd0042E04a63A67B02471afeB0b15eb", Private: "e05b811022a268d8382fccdf11dbeafa61f7c2eaba56bfdcc8c9408543628c69", Public: "0x11E88086EAd0042E04a63A67B02471afeB0b15eb"},
{Address: "0x3F510917bf1976Dc5De6396c534Dbe318B7146a2", Private: "69d13ca50a3fb4492476738a7571effe4cf55e8db1155de1327435460043a11f", Public: "0x3F510917bf1976Dc5De6396c534Dbe318B7146a2"},
{Address: "0x024bC87a26A3bB9cE7e18bCA2A2cDbDBAE42B12B", Private: "9271ae0561e8c002e273ccbdb389c11aac686a607af1ce33f8ed3a49975dd075", Public: "0x024bC87a26A3bB9cE7e18bCA2A2cDbDBAE42B12B"},
{Address: "0x960DF705848B2013DD6cf1E3F1376461dA8a24D6", Private: "f53ae08d87d744d45470b45ffff2af71269aef33033acf5344c7d4d8c64400d7", Public: "0x960DF705848B2013DD6cf1E3F1376461dA8a24D6"},
{Address: "0xb7F3F347a02BB6dFeF28d6A71197873e98E5942e", Private: "7cf030e2e75ccee0df0e462b20083cda1b164921816f55d7bb14642248933c64", Public: "0xb7F3F347a02BB6dFeF28d6A71197873e98E5942e"},
{Address: "0xc856Bb24116D617ba15881bcbdCC55B5a31996ae", Private: "8a6e9683ca8e980101260435b11357f4094fc3233772be38a75b653ad3983294", Public: "0xc856Bb24116D617ba15881bcbdCC55B5a31996ae"},
{Address: "0xf8FCE07DFFFd1E0B5fcc2f07116AC1E54AA7a27e", Private: "12ec787ab6667fbbc7ea23723b2e52d66452cacac09a574915600d85af24141a", Public: "0xf8FCE07DFFFd1E0B5fcc2f07116AC1E54AA7a27e"},
{Address: "0xf9b099054f28f2DE96DF8a46F8e2eFC07f110C45", Private: "ecaa786f451fa31ba74deb2bc6c0c02b85c3f52c0175f111daa750297fc426c9", Public: "0xf9b099054f28f2DE96DF8a46F8e2eFC07f110C45"},
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save