Remove unused code and add benchmark for consensus msg check (#3211)
parent
a168517dfc
commit
8a08da67ca
@ -1,23 +0,0 @@ |
|||||||
package client |
|
||||||
|
|
||||||
import ( |
|
||||||
"github.com/harmony-one/harmony/core/types" |
|
||||||
"github.com/harmony-one/harmony/p2p" |
|
||||||
) |
|
||||||
|
|
||||||
// Client represents a node (e.g. a wallet) which sends transactions and receives responses from the harmony network
|
|
||||||
type Client struct { |
|
||||||
ShardID uint32 // ShardID
|
|
||||||
UpdateBlocks func([]*types.Block) // Closure function used to sync new block with the leader. Once the leader finishes the consensus on a new block, it will send it to the clients. Clients use this method to update their blockchain
|
|
||||||
|
|
||||||
// The p2p host used to send/receive p2p messages
|
|
||||||
host p2p.Host |
|
||||||
} |
|
||||||
|
|
||||||
// NewClient creates a new Client
|
|
||||||
func NewClient(host p2p.Host, shardID uint32) *Client { |
|
||||||
client := Client{} |
|
||||||
client.host = host |
|
||||||
client.ShardID = shardID |
|
||||||
return &client |
|
||||||
} |
|
@ -1,54 +0,0 @@ |
|||||||
package client |
|
||||||
|
|
||||||
import ( |
|
||||||
"context" |
|
||||||
"fmt" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common" |
|
||||||
proto "github.com/harmony-one/harmony/api/client/service/proto" |
|
||||||
|
|
||||||
"google.golang.org/grpc" |
|
||||||
) |
|
||||||
|
|
||||||
// Client is the client model for client service.
|
|
||||||
type Client struct { |
|
||||||
clientServiceClient proto.ClientServiceClient |
|
||||||
opts []grpc.DialOption |
|
||||||
conn *grpc.ClientConn |
|
||||||
} |
|
||||||
|
|
||||||
// NewClient setups a Client given ip and port.
|
|
||||||
func NewClient(ip, port string) (*Client, error) { |
|
||||||
client := Client{} |
|
||||||
client.opts = append(client.opts, grpc.WithInsecure()) |
|
||||||
var err error |
|
||||||
client.conn, err = grpc.Dial(fmt.Sprintf("%s:%s", ip, port), client.opts...) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
|
|
||||||
client.clientServiceClient = proto.NewClientServiceClient(client.conn) |
|
||||||
return &client, nil |
|
||||||
} |
|
||||||
|
|
||||||
// Close closes the Client.
|
|
||||||
func (client *Client) Close() error { |
|
||||||
return client.conn.Close() |
|
||||||
} |
|
||||||
|
|
||||||
// GetBalance gets account balance from the client service.
|
|
||||||
func (client *Client) GetBalance(address common.Address) (*proto.FetchAccountStateResponse, error) { |
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
|
||||||
defer cancel() |
|
||||||
request := &proto.FetchAccountStateRequest{Address: address.Bytes()} |
|
||||||
return client.clientServiceClient.FetchAccountState(ctx, request) |
|
||||||
} |
|
||||||
|
|
||||||
// GetFreeToken requests free token from the faucet contract.
|
|
||||||
func (client *Client) GetFreeToken(address common.Address) (*proto.GetFreeTokenResponse, error) { |
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
|
||||||
defer cancel() |
|
||||||
request := &proto.GetFreeTokenRequest{Address: address.Bytes()} |
|
||||||
return client.clientServiceClient.GetFreeToken(ctx, request) |
|
||||||
} |
|
@ -1 +0,0 @@ |
|||||||
protoc -I proto/ proto/client.proto --go_out=plugins=grpc:proto |
|
@ -1,3 +0,0 @@ |
|||||||
package client |
|
||||||
|
|
||||||
//go:generate protoc client.proto --go_out=plugins=grpc:.
|
|
@ -1,344 +0,0 @@ |
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||||
// source: client.proto
|
|
||||||
|
|
||||||
package client |
|
||||||
|
|
||||||
import ( |
|
||||||
context "context" |
|
||||||
fmt "fmt" |
|
||||||
proto "github.com/golang/protobuf/proto" |
|
||||||
grpc "google.golang.org/grpc" |
|
||||||
codes "google.golang.org/grpc/codes" |
|
||||||
status "google.golang.org/grpc/status" |
|
||||||
math "math" |
|
||||||
) |
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal |
|
||||||
var _ = fmt.Errorf |
|
||||||
var _ = math.Inf |
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
|
||||||
|
|
||||||
// FetchAccountStateRequest is the request to fetch an account's balance and nonce.
|
|
||||||
type FetchAccountStateRequest struct { |
|
||||||
// The account address
|
|
||||||
Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` |
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"` |
|
||||||
XXX_unrecognized []byte `json:"-"` |
|
||||||
XXX_sizecache int32 `json:"-"` |
|
||||||
} |
|
||||||
|
|
||||||
func (m *FetchAccountStateRequest) Reset() { *m = FetchAccountStateRequest{} } |
|
||||||
func (m *FetchAccountStateRequest) String() string { return proto.CompactTextString(m) } |
|
||||||
func (*FetchAccountStateRequest) ProtoMessage() {} |
|
||||||
func (*FetchAccountStateRequest) Descriptor() ([]byte, []int) { |
|
||||||
return fileDescriptor_014de31d7ac8c57c, []int{0} |
|
||||||
} |
|
||||||
|
|
||||||
func (m *FetchAccountStateRequest) XXX_Unmarshal(b []byte) error { |
|
||||||
return xxx_messageInfo_FetchAccountStateRequest.Unmarshal(m, b) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { |
|
||||||
return xxx_messageInfo_FetchAccountStateRequest.Marshal(b, m, deterministic) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateRequest) XXX_Merge(src proto.Message) { |
|
||||||
xxx_messageInfo_FetchAccountStateRequest.Merge(m, src) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateRequest) XXX_Size() int { |
|
||||||
return xxx_messageInfo_FetchAccountStateRequest.Size(m) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateRequest) XXX_DiscardUnknown() { |
|
||||||
xxx_messageInfo_FetchAccountStateRequest.DiscardUnknown(m) |
|
||||||
} |
|
||||||
|
|
||||||
var xxx_messageInfo_FetchAccountStateRequest proto.InternalMessageInfo |
|
||||||
|
|
||||||
func (m *FetchAccountStateRequest) GetAddress() []byte { |
|
||||||
if m != nil { |
|
||||||
return m.Address |
|
||||||
} |
|
||||||
return nil |
|
||||||
} |
|
||||||
|
|
||||||
// FetchAccountStateResponse is the response of FetchAccountStateRequest.
|
|
||||||
type FetchAccountStateResponse struct { |
|
||||||
// The balance of the account (big.Int)
|
|
||||||
Balance []byte `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"` |
|
||||||
// The nonce of the account
|
|
||||||
Nonce uint64 `protobuf:"varint,2,opt,name=nonce,proto3" json:"nonce,omitempty"` |
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"` |
|
||||||
XXX_unrecognized []byte `json:"-"` |
|
||||||
XXX_sizecache int32 `json:"-"` |
|
||||||
} |
|
||||||
|
|
||||||
func (m *FetchAccountStateResponse) Reset() { *m = FetchAccountStateResponse{} } |
|
||||||
func (m *FetchAccountStateResponse) String() string { return proto.CompactTextString(m) } |
|
||||||
func (*FetchAccountStateResponse) ProtoMessage() {} |
|
||||||
func (*FetchAccountStateResponse) Descriptor() ([]byte, []int) { |
|
||||||
return fileDescriptor_014de31d7ac8c57c, []int{1} |
|
||||||
} |
|
||||||
|
|
||||||
func (m *FetchAccountStateResponse) XXX_Unmarshal(b []byte) error { |
|
||||||
return xxx_messageInfo_FetchAccountStateResponse.Unmarshal(m, b) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { |
|
||||||
return xxx_messageInfo_FetchAccountStateResponse.Marshal(b, m, deterministic) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateResponse) XXX_Merge(src proto.Message) { |
|
||||||
xxx_messageInfo_FetchAccountStateResponse.Merge(m, src) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateResponse) XXX_Size() int { |
|
||||||
return xxx_messageInfo_FetchAccountStateResponse.Size(m) |
|
||||||
} |
|
||||||
func (m *FetchAccountStateResponse) XXX_DiscardUnknown() { |
|
||||||
xxx_messageInfo_FetchAccountStateResponse.DiscardUnknown(m) |
|
||||||
} |
|
||||||
|
|
||||||
var xxx_messageInfo_FetchAccountStateResponse proto.InternalMessageInfo |
|
||||||
|
|
||||||
func (m *FetchAccountStateResponse) GetBalance() []byte { |
|
||||||
if m != nil { |
|
||||||
return m.Balance |
|
||||||
} |
|
||||||
return nil |
|
||||||
} |
|
||||||
|
|
||||||
func (m *FetchAccountStateResponse) GetNonce() uint64 { |
|
||||||
if m != nil { |
|
||||||
return m.Nonce |
|
||||||
} |
|
||||||
return 0 |
|
||||||
} |
|
||||||
|
|
||||||
// GetFreeTokenRequest is the request to get free token from the faucet smart contract.
|
|
||||||
type GetFreeTokenRequest struct { |
|
||||||
// The account address to receive the free token
|
|
||||||
Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` |
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"` |
|
||||||
XXX_unrecognized []byte `json:"-"` |
|
||||||
XXX_sizecache int32 `json:"-"` |
|
||||||
} |
|
||||||
|
|
||||||
func (m *GetFreeTokenRequest) Reset() { *m = GetFreeTokenRequest{} } |
|
||||||
func (m *GetFreeTokenRequest) String() string { return proto.CompactTextString(m) } |
|
||||||
func (*GetFreeTokenRequest) ProtoMessage() {} |
|
||||||
func (*GetFreeTokenRequest) Descriptor() ([]byte, []int) { |
|
||||||
return fileDescriptor_014de31d7ac8c57c, []int{2} |
|
||||||
} |
|
||||||
|
|
||||||
func (m *GetFreeTokenRequest) XXX_Unmarshal(b []byte) error { |
|
||||||
return xxx_messageInfo_GetFreeTokenRequest.Unmarshal(m, b) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { |
|
||||||
return xxx_messageInfo_GetFreeTokenRequest.Marshal(b, m, deterministic) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenRequest) XXX_Merge(src proto.Message) { |
|
||||||
xxx_messageInfo_GetFreeTokenRequest.Merge(m, src) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenRequest) XXX_Size() int { |
|
||||||
return xxx_messageInfo_GetFreeTokenRequest.Size(m) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenRequest) XXX_DiscardUnknown() { |
|
||||||
xxx_messageInfo_GetFreeTokenRequest.DiscardUnknown(m) |
|
||||||
} |
|
||||||
|
|
||||||
var xxx_messageInfo_GetFreeTokenRequest proto.InternalMessageInfo |
|
||||||
|
|
||||||
func (m *GetFreeTokenRequest) GetAddress() []byte { |
|
||||||
if m != nil { |
|
||||||
return m.Address |
|
||||||
} |
|
||||||
return nil |
|
||||||
} |
|
||||||
|
|
||||||
// GetFreeTokenResponse is the response of GetFreeTokenRequest.
|
|
||||||
type GetFreeTokenResponse struct { |
|
||||||
// The transaction Id that requests free token from the faucet.
|
|
||||||
TxId []byte `protobuf:"bytes,1,opt,name=txId,proto3" json:"txId,omitempty"` |
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"` |
|
||||||
XXX_unrecognized []byte `json:"-"` |
|
||||||
XXX_sizecache int32 `json:"-"` |
|
||||||
} |
|
||||||
|
|
||||||
func (m *GetFreeTokenResponse) Reset() { *m = GetFreeTokenResponse{} } |
|
||||||
func (m *GetFreeTokenResponse) String() string { return proto.CompactTextString(m) } |
|
||||||
func (*GetFreeTokenResponse) ProtoMessage() {} |
|
||||||
func (*GetFreeTokenResponse) Descriptor() ([]byte, []int) { |
|
||||||
return fileDescriptor_014de31d7ac8c57c, []int{3} |
|
||||||
} |
|
||||||
|
|
||||||
func (m *GetFreeTokenResponse) XXX_Unmarshal(b []byte) error { |
|
||||||
return xxx_messageInfo_GetFreeTokenResponse.Unmarshal(m, b) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { |
|
||||||
return xxx_messageInfo_GetFreeTokenResponse.Marshal(b, m, deterministic) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenResponse) XXX_Merge(src proto.Message) { |
|
||||||
xxx_messageInfo_GetFreeTokenResponse.Merge(m, src) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenResponse) XXX_Size() int { |
|
||||||
return xxx_messageInfo_GetFreeTokenResponse.Size(m) |
|
||||||
} |
|
||||||
func (m *GetFreeTokenResponse) XXX_DiscardUnknown() { |
|
||||||
xxx_messageInfo_GetFreeTokenResponse.DiscardUnknown(m) |
|
||||||
} |
|
||||||
|
|
||||||
var xxx_messageInfo_GetFreeTokenResponse proto.InternalMessageInfo |
|
||||||
|
|
||||||
func (m *GetFreeTokenResponse) GetTxId() []byte { |
|
||||||
if m != nil { |
|
||||||
return m.TxId |
|
||||||
} |
|
||||||
return nil |
|
||||||
} |
|
||||||
|
|
||||||
func init() { |
|
||||||
proto.RegisterType((*FetchAccountStateRequest)(nil), "client.FetchAccountStateRequest") |
|
||||||
proto.RegisterType((*FetchAccountStateResponse)(nil), "client.FetchAccountStateResponse") |
|
||||||
proto.RegisterType((*GetFreeTokenRequest)(nil), "client.GetFreeTokenRequest") |
|
||||||
proto.RegisterType((*GetFreeTokenResponse)(nil), "client.GetFreeTokenResponse") |
|
||||||
} |
|
||||||
|
|
||||||
func init() { |
|
||||||
proto.RegisterFile("client.proto", fileDescriptor_014de31d7ac8c57c) |
|
||||||
} |
|
||||||
|
|
||||||
var fileDescriptor_014de31d7ac8c57c = []byte{ |
|
||||||
// 229 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0xc9, 0x4c, |
|
||||||
0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x4c, 0xb8, 0x24, |
|
||||||
0xdc, 0x52, 0x4b, 0x92, 0x33, 0x1c, 0x93, 0x93, 0xf3, 0x4b, 0xf3, 0x4a, 0x82, 0x4b, 0x12, 0x4b, |
|
||||||
0x52, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x24, 0xb8, 0xd8, 0x13, 0x53, 0x52, 0x8a, |
|
||||||
0x52, 0x8b, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x78, 0x82, 0x60, 0x5c, 0x25, 0x6f, 0x2e, 0x49, |
|
||||||
0x2c, 0xba, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x41, 0xda, 0x92, 0x12, 0x73, 0x12, 0xf3, 0x92, |
|
||||||
0x53, 0x61, 0xda, 0xa0, 0x5c, 0x21, 0x11, 0x2e, 0xd6, 0xbc, 0x7c, 0x90, 0x38, 0x93, 0x02, 0xa3, |
|
||||||
0x06, 0x4b, 0x10, 0x84, 0xa3, 0xa4, 0xcf, 0x25, 0xec, 0x9e, 0x5a, 0xe2, 0x56, 0x94, 0x9a, 0x1a, |
|
||||||
0x92, 0x9f, 0x9d, 0x9a, 0x47, 0xd8, 0x76, 0x2d, 0x2e, 0x11, 0x54, 0x0d, 0x50, 0x8b, 0x85, 0xb8, |
|
||||||
0x58, 0x4a, 0x2a, 0x3c, 0x53, 0xa0, 0xca, 0xc1, 0x6c, 0xa3, 0x1d, 0x8c, 0x5c, 0xbc, 0xce, 0x60, |
|
||||||
0xaf, 0x06, 0xa7, 0x16, 0x95, 0x65, 0x26, 0xa7, 0x0a, 0x45, 0x71, 0x09, 0x62, 0xb8, 0x5d, 0x48, |
|
||||||
0x41, 0x0f, 0x1a, 0x3a, 0xb8, 0x02, 0x43, 0x4a, 0x11, 0x8f, 0x0a, 0x88, 0xfd, 0x4a, 0x0c, 0x42, |
|
||||||
0xde, 0x5c, 0x3c, 0xc8, 0x2e, 0x13, 0x92, 0x86, 0x69, 0xc2, 0xe2, 0x41, 0x29, 0x19, 0xec, 0x92, |
|
||||||
0x30, 0xc3, 0x92, 0xd8, 0xc0, 0x31, 0x65, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xc6, 0xd9, 0x35, |
|
||||||
0x0c, 0xb9, 0x01, 0x00, 0x00, |
|
||||||
} |
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ context.Context |
|
||||||
var _ grpc.ClientConnInterface |
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion6 |
|
||||||
|
|
||||||
// ClientServiceClient is the client API for ClientService service.
|
|
||||||
//
|
|
||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
|
||||||
type ClientServiceClient interface { |
|
||||||
FetchAccountState(ctx context.Context, in *FetchAccountStateRequest, opts ...grpc.CallOption) (*FetchAccountStateResponse, error) |
|
||||||
GetFreeToken(ctx context.Context, in *GetFreeTokenRequest, opts ...grpc.CallOption) (*GetFreeTokenResponse, error) |
|
||||||
} |
|
||||||
|
|
||||||
type clientServiceClient struct { |
|
||||||
cc grpc.ClientConnInterface |
|
||||||
} |
|
||||||
|
|
||||||
func NewClientServiceClient(cc grpc.ClientConnInterface) ClientServiceClient { |
|
||||||
return &clientServiceClient{cc} |
|
||||||
} |
|
||||||
|
|
||||||
func (c *clientServiceClient) FetchAccountState(ctx context.Context, in *FetchAccountStateRequest, opts ...grpc.CallOption) (*FetchAccountStateResponse, error) { |
|
||||||
out := new(FetchAccountStateResponse) |
|
||||||
err := c.cc.Invoke(ctx, "/client.ClientService/FetchAccountState", in, out, opts...) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return out, nil |
|
||||||
} |
|
||||||
|
|
||||||
func (c *clientServiceClient) GetFreeToken(ctx context.Context, in *GetFreeTokenRequest, opts ...grpc.CallOption) (*GetFreeTokenResponse, error) { |
|
||||||
out := new(GetFreeTokenResponse) |
|
||||||
err := c.cc.Invoke(ctx, "/client.ClientService/GetFreeToken", in, out, opts...) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return out, nil |
|
||||||
} |
|
||||||
|
|
||||||
// ClientServiceServer is the server API for ClientService service.
|
|
||||||
type ClientServiceServer interface { |
|
||||||
FetchAccountState(context.Context, *FetchAccountStateRequest) (*FetchAccountStateResponse, error) |
|
||||||
GetFreeToken(context.Context, *GetFreeTokenRequest) (*GetFreeTokenResponse, error) |
|
||||||
} |
|
||||||
|
|
||||||
// UnimplementedClientServiceServer can be embedded to have forward compatible implementations.
|
|
||||||
type UnimplementedClientServiceServer struct { |
|
||||||
} |
|
||||||
|
|
||||||
func (*UnimplementedClientServiceServer) FetchAccountState(ctx context.Context, req *FetchAccountStateRequest) (*FetchAccountStateResponse, error) { |
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method FetchAccountState not implemented") |
|
||||||
} |
|
||||||
func (*UnimplementedClientServiceServer) GetFreeToken(ctx context.Context, req *GetFreeTokenRequest) (*GetFreeTokenResponse, error) { |
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method GetFreeToken not implemented") |
|
||||||
} |
|
||||||
|
|
||||||
func RegisterClientServiceServer(s *grpc.Server, srv ClientServiceServer) { |
|
||||||
s.RegisterService(&_ClientService_serviceDesc, srv) |
|
||||||
} |
|
||||||
|
|
||||||
func _ClientService_FetchAccountState_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
|
||||||
in := new(FetchAccountStateRequest) |
|
||||||
if err := dec(in); err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
if interceptor == nil { |
|
||||||
return srv.(ClientServiceServer).FetchAccountState(ctx, in) |
|
||||||
} |
|
||||||
info := &grpc.UnaryServerInfo{ |
|
||||||
Server: srv, |
|
||||||
FullMethod: "/client.ClientService/FetchAccountState", |
|
||||||
} |
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
|
||||||
return srv.(ClientServiceServer).FetchAccountState(ctx, req.(*FetchAccountStateRequest)) |
|
||||||
} |
|
||||||
return interceptor(ctx, in, info, handler) |
|
||||||
} |
|
||||||
|
|
||||||
func _ClientService_GetFreeToken_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
|
||||||
in := new(GetFreeTokenRequest) |
|
||||||
if err := dec(in); err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
if interceptor == nil { |
|
||||||
return srv.(ClientServiceServer).GetFreeToken(ctx, in) |
|
||||||
} |
|
||||||
info := &grpc.UnaryServerInfo{ |
|
||||||
Server: srv, |
|
||||||
FullMethod: "/client.ClientService/GetFreeToken", |
|
||||||
} |
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
|
||||||
return srv.(ClientServiceServer).GetFreeToken(ctx, req.(*GetFreeTokenRequest)) |
|
||||||
} |
|
||||||
return interceptor(ctx, in, info, handler) |
|
||||||
} |
|
||||||
|
|
||||||
var _ClientService_serviceDesc = grpc.ServiceDesc{ |
|
||||||
ServiceName: "client.ClientService", |
|
||||||
HandlerType: (*ClientServiceServer)(nil), |
|
||||||
Methods: []grpc.MethodDesc{ |
|
||||||
{ |
|
||||||
MethodName: "FetchAccountState", |
|
||||||
Handler: _ClientService_FetchAccountState_Handler, |
|
||||||
}, |
|
||||||
{ |
|
||||||
MethodName: "GetFreeToken", |
|
||||||
Handler: _ClientService_GetFreeToken_Handler, |
|
||||||
}, |
|
||||||
}, |
|
||||||
Streams: []grpc.StreamDesc{}, |
|
||||||
Metadata: "client.proto", |
|
||||||
} |
|
@ -1,35 +0,0 @@ |
|||||||
syntax = "proto3"; |
|
||||||
|
|
||||||
package client; |
|
||||||
|
|
||||||
// Client is the service used for any client-facing requests. |
|
||||||
service ClientService { |
|
||||||
rpc FetchAccountState(FetchAccountStateRequest) returns (FetchAccountStateResponse) {} |
|
||||||
rpc GetFreeToken(GetFreeTokenRequest) returns (GetFreeTokenResponse) {} |
|
||||||
} |
|
||||||
|
|
||||||
// FetchAccountStateRequest is the request to fetch an account's balance and nonce. |
|
||||||
message FetchAccountStateRequest { |
|
||||||
// The account address |
|
||||||
bytes address = 1; |
|
||||||
} |
|
||||||
|
|
||||||
// FetchAccountStateResponse is the response of FetchAccountStateRequest. |
|
||||||
message FetchAccountStateResponse { |
|
||||||
// The balance of the account (big.Int) |
|
||||||
bytes balance = 1; |
|
||||||
// The nonce of the account |
|
||||||
uint64 nonce = 2; |
|
||||||
} |
|
||||||
|
|
||||||
// GetFreeTokenRequest is the request to get free token from the faucet smart contract. |
|
||||||
message GetFreeTokenRequest { |
|
||||||
// The account address to receive the free token |
|
||||||
bytes address = 1; |
|
||||||
} |
|
||||||
|
|
||||||
// GetFreeTokenResponse is the response of GetFreeTokenRequest. |
|
||||||
message GetFreeTokenResponse { |
|
||||||
// The transaction Id that requests free token from the faucet. |
|
||||||
bytes txId = 1; |
|
||||||
} |
|
@ -1,70 +0,0 @@ |
|||||||
package client |
|
||||||
|
|
||||||
import ( |
|
||||||
"context" |
|
||||||
"log" |
|
||||||
"net" |
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common" |
|
||||||
proto "github.com/harmony-one/harmony/api/client/service/proto" |
|
||||||
"github.com/harmony-one/harmony/core/state" |
|
||||||
"github.com/harmony-one/harmony/internal/utils" |
|
||||||
|
|
||||||
"google.golang.org/grpc" |
|
||||||
) |
|
||||||
|
|
||||||
// Server is the Server struct for client service package.
|
|
||||||
type Server struct { |
|
||||||
stateReader func() (*state.DB, error) |
|
||||||
callFaucetContract func(common.Address) common.Hash |
|
||||||
} |
|
||||||
|
|
||||||
// FetchAccountState implements the FetchAccountState interface to return account state.
|
|
||||||
func (s *Server) FetchAccountState(ctx context.Context, request *proto.FetchAccountStateRequest) (*proto.FetchAccountStateResponse, error) { |
|
||||||
var address common.Address |
|
||||||
address.SetBytes(request.Address) |
|
||||||
// log.Println("Returning FetchAccountStateResponse for address: ", address.Hex())
|
|
||||||
state, err := s.stateReader() |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return &proto.FetchAccountStateResponse{Balance: state.GetBalance(address).Bytes(), Nonce: state.GetNonce(address)}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// GetFreeToken implements the GetFreeToken interface to request free token.
|
|
||||||
func (s *Server) GetFreeToken(ctx context.Context, request *proto.GetFreeTokenRequest) (*proto.GetFreeTokenResponse, error) { |
|
||||||
var address common.Address |
|
||||||
address.SetBytes(request.Address) |
|
||||||
// log.Println("Returning GetFreeTokenResponse for address: ", address.Hex())
|
|
||||||
return &proto.GetFreeTokenResponse{TxId: s.callFaucetContract(address).Bytes()}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// Start starts the Server on given ip and port.
|
|
||||||
func (s *Server) Start(ip, port string) (*grpc.Server, error) { |
|
||||||
// TODO(minhdoan): Currently not using ip. Fix it later.
|
|
||||||
addr := net.JoinHostPort("", port) |
|
||||||
lis, err := net.Listen("tcp4", addr) |
|
||||||
if err != nil { |
|
||||||
log.Fatalf("failed to listen: %v", err) |
|
||||||
} |
|
||||||
var opts []grpc.ServerOption |
|
||||||
grpcServer := grpc.NewServer(opts...) |
|
||||||
proto.RegisterClientServiceServer(grpcServer, s) |
|
||||||
go func() { |
|
||||||
if err := grpcServer.Serve(lis); err != nil { |
|
||||||
utils.Logger().Warn().Err(err).Msg("grpcServer.Serve() failed") |
|
||||||
} |
|
||||||
}() |
|
||||||
return grpcServer, nil |
|
||||||
} |
|
||||||
|
|
||||||
// NewServer creates new Server which implements ClientServiceServer interface.
|
|
||||||
func NewServer( |
|
||||||
stateReader func() (*state.DB, error), |
|
||||||
callFaucetContract func(common.Address) common.Hash) *Server { |
|
||||||
s := &Server{ |
|
||||||
stateReader: stateReader, |
|
||||||
callFaucetContract: callFaucetContract, |
|
||||||
} |
|
||||||
return s |
|
||||||
} |
|
@ -1,60 +0,0 @@ |
|||||||
package clientsupport |
|
||||||
|
|
||||||
import ( |
|
||||||
"strconv" |
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common" |
|
||||||
"github.com/ethereum/go-ethereum/rpc" |
|
||||||
clientService "github.com/harmony-one/harmony/api/client/service" |
|
||||||
msg_pb "github.com/harmony-one/harmony/api/proto/message" |
|
||||||
"github.com/harmony-one/harmony/core/state" |
|
||||||
"google.golang.org/grpc" |
|
||||||
) |
|
||||||
|
|
||||||
const ( |
|
||||||
// ClientServicePortDiff is the positive port diff for client service
|
|
||||||
ClientServicePortDiff = 5555 |
|
||||||
) |
|
||||||
|
|
||||||
// Service is the client support service.
|
|
||||||
type Service struct { |
|
||||||
server *clientService.Server |
|
||||||
grpcServer *grpc.Server |
|
||||||
ip string |
|
||||||
port string |
|
||||||
messageChan chan *msg_pb.Message |
|
||||||
} |
|
||||||
|
|
||||||
// New returns new client support service.
|
|
||||||
func New(stateReader func() (*state.DB, error), |
|
||||||
callFaucetContract func(common.Address) common.Hash, |
|
||||||
ip, nodePort string) *Service { |
|
||||||
port, _ := strconv.Atoi(nodePort) |
|
||||||
return &Service{ |
|
||||||
server: clientService.NewServer(stateReader, callFaucetContract), |
|
||||||
ip: ip, |
|
||||||
port: strconv.Itoa(port + ClientServicePortDiff)} |
|
||||||
} |
|
||||||
|
|
||||||
// StartService starts client support service.
|
|
||||||
func (s *Service) StartService() { |
|
||||||
s.grpcServer, _ = s.server.Start(s.ip, s.port) |
|
||||||
} |
|
||||||
|
|
||||||
// StopService stops client support service.
|
|
||||||
func (s *Service) StopService() { |
|
||||||
s.grpcServer.Stop() |
|
||||||
} |
|
||||||
|
|
||||||
// SetMessageChan sets up message channel to service.
|
|
||||||
func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) { |
|
||||||
s.messageChan = messageChan |
|
||||||
} |
|
||||||
|
|
||||||
// NotifyService notify service
|
|
||||||
func (s *Service) NotifyService(params map[string]interface{}) {} |
|
||||||
|
|
||||||
// APIs for the services.
|
|
||||||
func (s *Service) APIs() []rpc.API { |
|
||||||
return nil |
|
||||||
} |
|
@ -1,236 +0,0 @@ |
|||||||
// Code generated - DO NOT EDIT.
|
|
||||||
// This file is a generated binding and any manual changes will be lost.
|
|
||||||
|
|
||||||
package contracts |
|
||||||
|
|
||||||
import ( |
|
||||||
"math/big" |
|
||||||
"strings" |
|
||||||
|
|
||||||
ethereum "github.com/ethereum/go-ethereum" |
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi" |
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind" |
|
||||||
"github.com/ethereum/go-ethereum/common" |
|
||||||
"github.com/ethereum/go-ethereum/core/types" |
|
||||||
"github.com/ethereum/go-ethereum/event" |
|
||||||
) |
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var ( |
|
||||||
_ = big.NewInt |
|
||||||
_ = strings.NewReader |
|
||||||
_ = ethereum.NotFound |
|
||||||
_ = abi.U256 |
|
||||||
_ = bind.Bind |
|
||||||
_ = common.Big1 |
|
||||||
_ = types.BloomLookup |
|
||||||
_ = event.NewSubscription |
|
||||||
) |
|
||||||
|
|
||||||
// FaucetABI is the input ABI used to generate the binding from.
|
|
||||||
const FaucetABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"requestor\",\"type\":\"address\"}],\"name\":\"request\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"money\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]" |
|
||||||
|
|
||||||
// FaucetBin is the compiled bytecode used for deploying new contracts.
|
|
||||||
const FaucetBin = `0x608060405268056bc75e2d63100000600155600280546001600160a01b0319163317905561014d806100326000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806327c78c421461003b5780634ddd108a14610063575b600080fd5b6100616004803603602081101561005157600080fd5b50356001600160a01b031661007d565b005b61006b61011c565b60408051918252519081900360200190f35b6002546001600160a01b0316331461009457600080fd5b600154303110156100a457600080fd5b6001600160a01b03811660009081526020819052604090205460ff16156100ca57600080fd5b6001600160a01b038116600081815260208190526040808220805460ff1916600190811790915554905181156108fc0292818181858888f19350505050158015610118573d6000803e3d6000fd5b5050565b30319056fea165627a7a72305820fff2e3fdb95fb4beeaf0ea0cf53af65742d33136d84f4511dccb95696c1d0c140029` |
|
||||||
|
|
||||||
// DeployFaucet deploys a new Ethereum contract, binding an instance of Faucet to it.
|
|
||||||
func DeployFaucet(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *Faucet, error) { |
|
||||||
parsed, err := abi.JSON(strings.NewReader(FaucetABI)) |
|
||||||
if err != nil { |
|
||||||
return common.Address{}, nil, nil, err |
|
||||||
} |
|
||||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(FaucetBin), backend) |
|
||||||
if err != nil { |
|
||||||
return common.Address{}, nil, nil, err |
|
||||||
} |
|
||||||
return address, tx, &Faucet{FaucetCaller: FaucetCaller{contract: contract}, FaucetTransactor: FaucetTransactor{contract: contract}, FaucetFilterer: FaucetFilterer{contract: contract}}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// Faucet is an auto generated Go binding around an Ethereum contract.
|
|
||||||
type Faucet struct { |
|
||||||
FaucetCaller // Read-only binding to the contract
|
|
||||||
FaucetTransactor // Write-only binding to the contract
|
|
||||||
FaucetFilterer // Log filterer for contract events
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetCaller is an auto generated read-only Go binding around an Ethereum contract.
|
|
||||||
type FaucetCaller struct { |
|
||||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
|
||||||
type FaucetTransactor struct { |
|
||||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
|
||||||
type FaucetFilterer struct { |
|
||||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetSession is an auto generated Go binding around an Ethereum contract,
|
|
||||||
// with pre-set call and transact options.
|
|
||||||
type FaucetSession struct { |
|
||||||
Contract *Faucet // Generic contract binding to set the session for
|
|
||||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
|
||||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
|
||||||
// with pre-set call options.
|
|
||||||
type FaucetCallerSession struct { |
|
||||||
Contract *FaucetCaller // Generic contract caller binding to set the session for
|
|
||||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
|
||||||
// with pre-set transact options.
|
|
||||||
type FaucetTransactorSession struct { |
|
||||||
Contract *FaucetTransactor // Generic contract transactor binding to set the session for
|
|
||||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetRaw is an auto generated low-level Go binding around an Ethereum contract.
|
|
||||||
type FaucetRaw struct { |
|
||||||
Contract *Faucet // Generic contract binding to access the raw methods on
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
|
||||||
type FaucetCallerRaw struct { |
|
||||||
Contract *FaucetCaller // Generic read-only contract binding to access the raw methods on
|
|
||||||
} |
|
||||||
|
|
||||||
// FaucetTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
|
||||||
type FaucetTransactorRaw struct { |
|
||||||
Contract *FaucetTransactor // Generic write-only contract binding to access the raw methods on
|
|
||||||
} |
|
||||||
|
|
||||||
// NewFaucet creates a new instance of Faucet, bound to a specific deployed contract.
|
|
||||||
func NewFaucet(address common.Address, backend bind.ContractBackend) (*Faucet, error) { |
|
||||||
contract, err := bindFaucet(address, backend, backend, backend) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return &Faucet{FaucetCaller: FaucetCaller{contract: contract}, FaucetTransactor: FaucetTransactor{contract: contract}, FaucetFilterer: FaucetFilterer{contract: contract}}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// NewFaucetCaller creates a new read-only instance of Faucet, bound to a specific deployed contract.
|
|
||||||
func NewFaucetCaller(address common.Address, caller bind.ContractCaller) (*FaucetCaller, error) { |
|
||||||
contract, err := bindFaucet(address, caller, nil, nil) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return &FaucetCaller{contract: contract}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// NewFaucetTransactor creates a new write-only instance of Faucet, bound to a specific deployed contract.
|
|
||||||
func NewFaucetTransactor(address common.Address, transactor bind.ContractTransactor) (*FaucetTransactor, error) { |
|
||||||
contract, err := bindFaucet(address, nil, transactor, nil) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return &FaucetTransactor{contract: contract}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// NewFaucetFilterer creates a new log filterer instance of Faucet, bound to a specific deployed contract.
|
|
||||||
func NewFaucetFilterer(address common.Address, filterer bind.ContractFilterer) (*FaucetFilterer, error) { |
|
||||||
contract, err := bindFaucet(address, nil, nil, filterer) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return &FaucetFilterer{contract: contract}, nil |
|
||||||
} |
|
||||||
|
|
||||||
// bindFaucet binds a generic wrapper to an already deployed contract.
|
|
||||||
func bindFaucet(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { |
|
||||||
parsed, err := abi.JSON(strings.NewReader(FaucetABI)) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil |
|
||||||
} |
|
||||||
|
|
||||||
// Call invokes the (constant) contract method with params as input values and
|
|
||||||
// sets the output to result. The result type might be a single field for simple
|
|
||||||
// returns, a slice of interfaces for anonymous returns and a struct for named
|
|
||||||
// returns.
|
|
||||||
func (_Faucet *FaucetRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { |
|
||||||
return _Faucet.Contract.FaucetCaller.contract.Call(opts, result, method, params...) |
|
||||||
} |
|
||||||
|
|
||||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
|
||||||
// its default method if one is available.
|
|
||||||
func (_Faucet *FaucetRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { |
|
||||||
return _Faucet.Contract.FaucetTransactor.contract.Transfer(opts) |
|
||||||
} |
|
||||||
|
|
||||||
// Transact invokes the (paid) contract method with params as input values.
|
|
||||||
func (_Faucet *FaucetRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { |
|
||||||
return _Faucet.Contract.FaucetTransactor.contract.Transact(opts, method, params...) |
|
||||||
} |
|
||||||
|
|
||||||
// Call invokes the (constant) contract method with params as input values and
|
|
||||||
// sets the output to result. The result type might be a single field for simple
|
|
||||||
// returns, a slice of interfaces for anonymous returns and a struct for named
|
|
||||||
// returns.
|
|
||||||
func (_Faucet *FaucetCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { |
|
||||||
return _Faucet.Contract.contract.Call(opts, result, method, params...) |
|
||||||
} |
|
||||||
|
|
||||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
|
||||||
// its default method if one is available.
|
|
||||||
func (_Faucet *FaucetTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { |
|
||||||
return _Faucet.Contract.contract.Transfer(opts) |
|
||||||
} |
|
||||||
|
|
||||||
// Transact invokes the (paid) contract method with params as input values.
|
|
||||||
func (_Faucet *FaucetTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { |
|
||||||
return _Faucet.Contract.contract.Transact(opts, method, params...) |
|
||||||
} |
|
||||||
|
|
||||||
// Money is a free data retrieval call binding the contract method 0x4ddd108a.
|
|
||||||
//
|
|
||||||
// Solidity: function money() constant returns(uint256)
|
|
||||||
func (_Faucet *FaucetCaller) Money(opts *bind.CallOpts) (*big.Int, error) { |
|
||||||
var ( |
|
||||||
ret0 = new(*big.Int) |
|
||||||
) |
|
||||||
out := ret0 |
|
||||||
err := _Faucet.contract.Call(opts, out, "money") |
|
||||||
return *ret0, err |
|
||||||
} |
|
||||||
|
|
||||||
// Money is a free data retrieval call binding the contract method 0x4ddd108a.
|
|
||||||
//
|
|
||||||
// Solidity: function money() constant returns(uint256)
|
|
||||||
func (_Faucet *FaucetSession) Money() (*big.Int, error) { |
|
||||||
return _Faucet.Contract.Money(&_Faucet.CallOpts) |
|
||||||
} |
|
||||||
|
|
||||||
// Money is a free data retrieval call binding the contract method 0x4ddd108a.
|
|
||||||
//
|
|
||||||
// Solidity: function money() constant returns(uint256)
|
|
||||||
func (_Faucet *FaucetCallerSession) Money() (*big.Int, error) { |
|
||||||
return _Faucet.Contract.Money(&_Faucet.CallOpts) |
|
||||||
} |
|
||||||
|
|
||||||
// Request is a paid mutator transaction binding the contract method 0x27c78c42.
|
|
||||||
//
|
|
||||||
// Solidity: function request(address requestor) returns()
|
|
||||||
func (_Faucet *FaucetTransactor) Request(opts *bind.TransactOpts, requestor common.Address) (*types.Transaction, error) { |
|
||||||
return _Faucet.contract.Transact(opts, "request", requestor) |
|
||||||
} |
|
||||||
|
|
||||||
// Request is a paid mutator transaction binding the contract method 0x27c78c42.
|
|
||||||
//
|
|
||||||
// Solidity: function request(address requestor) returns()
|
|
||||||
func (_Faucet *FaucetSession) Request(requestor common.Address) (*types.Transaction, error) { |
|
||||||
return _Faucet.Contract.Request(&_Faucet.TransactOpts, requestor) |
|
||||||
} |
|
||||||
|
|
||||||
// Request is a paid mutator transaction binding the contract method 0x27c78c42.
|
|
||||||
//
|
|
||||||
// Solidity: function request(address requestor) returns()
|
|
||||||
func (_Faucet *FaucetTransactorSession) Request(requestor common.Address) (*types.Transaction, error) { |
|
||||||
return _Faucet.Contract.Request(&_Faucet.TransactOpts, requestor) |
|
||||||
} |
|
@ -1,20 +0,0 @@ |
|||||||
pragma solidity >=0.4.22; |
|
||||||
|
|
||||||
contract Faucet { |
|
||||||
mapping(address => bool) processed; |
|
||||||
uint quota = 100 ether; |
|
||||||
address owner; |
|
||||||
constructor() public payable { |
|
||||||
owner = msg.sender; |
|
||||||
} |
|
||||||
function request(address payable requestor) public { |
|
||||||
require(msg.sender == owner); |
|
||||||
require(quota <= address(this).balance); |
|
||||||
require(!processed[requestor]); |
|
||||||
processed[requestor] = true; |
|
||||||
requestor.transfer(quota); |
|
||||||
} |
|
||||||
function money() public view returns(uint) { |
|
||||||
return address(this).balance; |
|
||||||
} |
|
||||||
} |
|
@ -1,5 +0,0 @@ |
|||||||
The smart contract files in this folder contains protocol-level smart contracts that are critical to the overall operation of Harmony protocol: |
|
||||||
|
|
||||||
- Faucet.sol is the smart contract to dispense free test tokens in our testnet. |
|
||||||
|
|
||||||
Solc is needed to recompile the contracts into ABI and bytecode. Please follow https://solidity.readthedocs.io/en/v0.5.3/installing-solidity.html for the installation. |
|
@ -1,19 +0,0 @@ |
|||||||
package core |
|
||||||
|
|
||||||
import ( |
|
||||||
"strings" |
|
||||||
"testing" |
|
||||||
) |
|
||||||
|
|
||||||
func TestEncodeGenesisConfig(t *testing.T) { |
|
||||||
fileName := "genesis_block_test.json" |
|
||||||
s := EncodeGenesisConfig(fileName) |
|
||||||
genesisAcc := decodePrealloc(s) |
|
||||||
|
|
||||||
for k := range genesisAcc { |
|
||||||
key := strings.ToLower(k.Hex()) |
|
||||||
if key != "0xb7a2c103728b7305b5ae6e961c94ee99c9fe8e2b" && key != "0xb498bb0f520005b6216a4425b75aa9adc52d622b" { |
|
||||||
t.Errorf("EncodeGenesisConfig incorrect") |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,101 +0,0 @@ |
|||||||
package node |
|
||||||
|
|
||||||
import ( |
|
||||||
"math/big" |
|
||||||
"strings" |
|
||||||
"sync/atomic" |
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi" |
|
||||||
"github.com/ethereum/go-ethereum/common" |
|
||||||
"github.com/ethereum/go-ethereum/crypto" |
|
||||||
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
||||||
"github.com/harmony-one/harmony/internal/params" |
|
||||||
|
|
||||||
"github.com/harmony-one/harmony/common/denominations" |
|
||||||
"github.com/harmony-one/harmony/contracts" |
|
||||||
"github.com/harmony-one/harmony/core/types" |
|
||||||
common2 "github.com/harmony-one/harmony/internal/common" |
|
||||||
"github.com/harmony-one/harmony/internal/utils" |
|
||||||
) |
|
||||||
|
|
||||||
// Constants related to smart contract.
|
|
||||||
const ( |
|
||||||
FaucetContractFund = 80000000 |
|
||||||
) |
|
||||||
|
|
||||||
// GetNonceOfAddress returns nonce of an address.
|
|
||||||
func (node *Node) GetNonceOfAddress(address common.Address) uint64 { |
|
||||||
state, err := node.Blockchain().State() |
|
||||||
if err != nil { |
|
||||||
utils.Logger().Error().Err(err).Msg("Failed to get chain state") |
|
||||||
return 0 |
|
||||||
} |
|
||||||
return state.GetNonce(address) |
|
||||||
} |
|
||||||
|
|
||||||
// GetBalanceOfAddress returns balance of an address.
|
|
||||||
func (node *Node) GetBalanceOfAddress(address common.Address) (*big.Int, error) { |
|
||||||
state, err := node.Blockchain().State() |
|
||||||
if err != nil { |
|
||||||
utils.Logger().Error().Err(err).Msg("Failed to get chain state") |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
balance := big.NewInt(0) |
|
||||||
balance.SetBytes(state.GetBalance(address).Bytes()) |
|
||||||
return balance, nil |
|
||||||
} |
|
||||||
|
|
||||||
// AddFaucetContractToPendingTransactions adds the faucet contract the genesis block.
|
|
||||||
func (node *Node) AddFaucetContractToPendingTransactions() { |
|
||||||
// Add a contract deployment transactionv
|
|
||||||
priKey := node.ContractDeployerKey |
|
||||||
dataEnc := common.FromHex(contracts.FaucetBin) |
|
||||||
// Unsigned transaction to avoid the case of transaction address.
|
|
||||||
|
|
||||||
contractFunds := big.NewInt(FaucetContractFund) |
|
||||||
contractFunds = contractFunds.Mul(contractFunds, big.NewInt(denominations.One)) |
|
||||||
mycontracttx, _ := types.SignTx( |
|
||||||
types.NewContractCreation(uint64(0), node.Consensus.ShardID, contractFunds, params.TxGasContractCreation*10, nil, dataEnc), |
|
||||||
types.HomesteadSigner{}, |
|
||||||
priKey) |
|
||||||
node.ContractAddresses = append(node.ContractAddresses, crypto.CreateAddress(crypto.PubkeyToAddress(priKey.PublicKey), uint64(0))) |
|
||||||
node.addPendingTransactions(types.Transactions{mycontracttx}) |
|
||||||
} |
|
||||||
|
|
||||||
// CallFaucetContract invokes the faucet contract to give the walletAddress initial money
|
|
||||||
func (node *Node) CallFaucetContract(address common.Address) common.Hash { |
|
||||||
if node.NodeConfig.GetNetworkType() == nodeconfig.Mainnet { |
|
||||||
return common.Hash{} |
|
||||||
} |
|
||||||
// Temporary code to workaround explorer issue for searching new addresses (https://github.com/harmony-one/harmony/issues/503)
|
|
||||||
nonce := atomic.AddUint64(&node.ContractDeployerCurrentNonce, 1) |
|
||||||
tx, _ := types.SignTx(types.NewTransaction(nonce-1, address, node.Consensus.ShardID, big.NewInt(0), params.TxGasContractCreation*10, nil, nil), types.HomesteadSigner{}, node.ContractDeployerKey) |
|
||||||
utils.Logger().Info().Str("Address", common2.MustAddressToBech32(address)).Msg("Sending placeholder token to ") |
|
||||||
node.addPendingTransactions(types.Transactions{tx}) |
|
||||||
// END Temporary code
|
|
||||||
|
|
||||||
nonce = atomic.AddUint64(&node.ContractDeployerCurrentNonce, 1) |
|
||||||
return node.callGetFreeTokenWithNonce(address, nonce-1) |
|
||||||
} |
|
||||||
|
|
||||||
func (node *Node) callGetFreeTokenWithNonce(address common.Address, nonce uint64) common.Hash { |
|
||||||
abi, err := abi.JSON(strings.NewReader(contracts.FaucetABI)) |
|
||||||
if err != nil { |
|
||||||
utils.Logger().Error().Err(err).Msg("Failed to generate faucet contract's ABI") |
|
||||||
return common.Hash{} |
|
||||||
} |
|
||||||
bytesData, err := abi.Pack("request", address) |
|
||||||
if err != nil { |
|
||||||
utils.Logger().Error().Err(err).Msg("Failed to generate ABI function bytes data") |
|
||||||
return common.Hash{} |
|
||||||
} |
|
||||||
if len(node.ContractAddresses) == 0 { |
|
||||||
utils.Logger().Error().Err(err).Msg("Failed to find the contract address") |
|
||||||
return common.Hash{} |
|
||||||
} |
|
||||||
tx, _ := types.SignTx(types.NewTransaction(nonce, node.ContractAddresses[0], node.Consensus.ShardID, big.NewInt(0), params.TxGasContractCreation*10, nil, bytesData), types.HomesteadSigner{}, node.ContractDeployerKey) |
|
||||||
utils.Logger().Info().Str("Address", common2.MustAddressToBech32(address)).Msg("Sending Free Token to ") |
|
||||||
|
|
||||||
node.addPendingTransactions(types.Transactions{tx}) |
|
||||||
return tx.Hash() |
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
package node |
|
||||||
|
|
||||||
import ( |
|
||||||
"math/rand" |
|
||||||
"time" |
|
||||||
) |
|
||||||
|
|
||||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
|
||||||
|
|
||||||
func init() { |
|
||||||
rand.Seed(time.Now().UnixNano()) |
|
||||||
} |
|
||||||
|
|
||||||
// GenerateRandomString generates a random string with given length
|
|
||||||
func GenerateRandomString(n int) string { |
|
||||||
b := make([]rune, n) |
|
||||||
for i := range b { |
|
||||||
b[i] = letterRunes[rand.Intn(len(letterRunes))] |
|
||||||
} |
|
||||||
return string(b) |
|
||||||
} |
|
@ -1,10 +0,0 @@ |
|||||||
package node |
|
||||||
|
|
||||||
import ( |
|
||||||
"github.com/harmony-one/harmony/p2p" |
|
||||||
) |
|
||||||
|
|
||||||
// GetHost returns the p2p host
|
|
||||||
func (node *Node) GetHost() p2p.Host { |
|
||||||
return node.host |
|
||||||
} |
|
Loading…
Reference in new issue