mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
Change prefix to xdc
This commit is contained in:
parent
239f9702ce
commit
f272b5d8cb
4 changed files with 47 additions and 19 deletions
|
|
@ -244,7 +244,7 @@ func (w *wizard) readPassword() string {
|
||||||
func (w *wizard) readAddress() *common.Address {
|
func (w *wizard) readAddress() *common.Address {
|
||||||
for {
|
for {
|
||||||
// Read the address from the user
|
// Read the address from the user
|
||||||
fmt.Printf("> 0x")
|
fmt.Printf("> xdc")
|
||||||
text, err := w.in.ReadString('\n')
|
text, err := w.in.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Failed to read user input", "err", err)
|
log.Crit("Failed to read user input", "err", err)
|
||||||
|
|
@ -269,7 +269,7 @@ func (w *wizard) readAddress() *common.Address {
|
||||||
func (w *wizard) readDefaultAddress(def common.Address) common.Address {
|
func (w *wizard) readDefaultAddress(def common.Address) common.Address {
|
||||||
for {
|
for {
|
||||||
// Read the address from the user
|
// Read the address from the user
|
||||||
fmt.Printf("> 0x")
|
fmt.Printf("> xdc")
|
||||||
text, err := w.in.ReadString('\n')
|
text, err := w.in.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Failed to read user input", "err", err)
|
log.Crit("Failed to read user input", "err", err)
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,16 @@ func ToHex(b []byte) string {
|
||||||
return "0x" + hex
|
return "0x" + hex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FromHex returns the bytes represented by the hexadecimal string s.
|
||||||
|
// s may be prefixed with "0x".
|
||||||
func FromHex(s string) []byte {
|
func FromHex(s string) []byte {
|
||||||
if len(s) > 1 {
|
if len(s) > 1 {
|
||||||
if s[0:2] == "0x" || s[0:2] == "0X" {
|
if s[0:2] == "0x" || s[0:2] == "0X" {
|
||||||
s = s[2:]
|
s = s[2:]
|
||||||
}
|
}
|
||||||
|
if (s[0] == 'x' || s[0] == 'X') && (s[1] == 'd' || s[1] == 'D') && (s[2] == 'c' || s[2] == 'C') {
|
||||||
|
s = s[3:]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(s)%2 == 1 {
|
if len(s)%2 == 1 {
|
||||||
s = "0" + s
|
s = "0" + s
|
||||||
|
|
@ -53,6 +58,10 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasXDCPrefix(str string) bool {
|
||||||
|
return len(str) >= 3 && (str[0] == 'x' || str[0] == 'X') && (str[1] == 'd' || str[1] == 'D') && (str[2] == 'c' || str[2] == 'C')
|
||||||
|
}
|
||||||
|
|
||||||
func hasHexPrefix(str string) bool {
|
func hasHexPrefix(str string) bool {
|
||||||
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
|
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,14 @@ func (b Bytes) MarshalText() ([]byte, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalXDCText implements encoding.TextMarshaler
|
||||||
|
func (b Bytes) MarshalXDCText() ([]byte, error) {
|
||||||
|
result := make([]byte, len(b)*2+3)
|
||||||
|
copy(result, `xdc`)
|
||||||
|
hex.Encode(result[3:], b)
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalJSON implements json.Unmarshaler.
|
// UnmarshalJSON implements json.Unmarshaler.
|
||||||
func (b *Bytes) UnmarshalJSON(input []byte) error {
|
func (b *Bytes) UnmarshalJSON(input []byte) error {
|
||||||
if !isString(input) {
|
if !isString(input) {
|
||||||
|
|
@ -277,12 +285,18 @@ func bytesHave0xPrefix(input []byte) bool {
|
||||||
return len(input) >= 2 && input[0] == '0' && (input[1] == 'x' || input[1] == 'X')
|
return len(input) >= 2 && input[0] == '0' && (input[1] == 'x' || input[1] == 'X')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bytesHaveXDCPrefix(input []byte) bool {
|
||||||
|
return len(input) >= 3 && (input[0] == 'x' || input[0] == 'X') && (input[1] == 'd' || input[1] == 'D') && (input[2] == 'c' || input[2] == 'C')
|
||||||
|
}
|
||||||
|
|
||||||
func checkText(input []byte, wantPrefix bool) ([]byte, error) {
|
func checkText(input []byte, wantPrefix bool) ([]byte, error) {
|
||||||
if len(input) == 0 {
|
if len(input) == 0 {
|
||||||
return nil, nil // empty strings are allowed
|
return nil, nil // empty strings are allowed
|
||||||
}
|
}
|
||||||
if bytesHave0xPrefix(input) {
|
if bytesHaveXDCPrefix(input) {
|
||||||
input = input[2:]
|
input = input[3:]
|
||||||
|
} else if bytesHave0xPrefix(input) {
|
||||||
|
input = input[2:]
|
||||||
} else if wantPrefix {
|
} else if wantPrefix {
|
||||||
return nil, ErrMissingPrefix
|
return nil, ErrMissingPrefix
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,15 +40,15 @@ func TestIsHexAddress(t *testing.T) {
|
||||||
str string
|
str string
|
||||||
exp bool
|
exp bool
|
||||||
}{
|
}{
|
||||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
{"xdc5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
||||||
{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
||||||
{"0X5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
{"XDC5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", true},
|
||||||
{"0XAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
|
{"XdcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
|
||||||
{"0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
|
{"xdcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", true},
|
||||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed1", false},
|
{"xdc5aaeb6053f3e94c9b9a09f33669435e7ef1beaed1", false},
|
||||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beae", false},
|
{"xdc5aaeb6053f3e94c9b9a09f33669435e7ef1beae", false},
|
||||||
{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed11", false},
|
{"5aaeb6053f3e94c9b9a09f33669435e7ef1beaed11", false},
|
||||||
{"0xxaaeb6053f3e94c9b9a09f33669435e7ef1beaed", false},
|
{"xdcxaaeb6053f3e94c9b9a09f33669435e7ef1beaed", false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
@ -101,6 +101,11 @@ func TestAddressUnmarshalJSON(t *testing.T) {
|
||||||
{`"0xG000000000000000000000000000000000000000"`, true, nil},
|
{`"0xG000000000000000000000000000000000000000"`, true, nil},
|
||||||
{`"0x0000000000000000000000000000000000000000"`, false, big.NewInt(0)},
|
{`"0x0000000000000000000000000000000000000000"`, false, big.NewInt(0)},
|
||||||
{`"0x0000000000000000000000000000000000000010"`, false, big.NewInt(16)},
|
{`"0x0000000000000000000000000000000000000010"`, false, big.NewInt(16)},
|
||||||
|
{`"xdc"`, true, nil},
|
||||||
|
{`"xdc00"`, true, nil},
|
||||||
|
{`"xdcG000000000000000000000000000000000000000"`, true, nil},
|
||||||
|
{`"xdc0000000000000000000000000000000000000000"`, false, big.NewInt(0)},
|
||||||
|
{`"xdc0000000000000000000000000000000000000010"`, false, big.NewInt(16)},
|
||||||
}
|
}
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
var v Address
|
var v Address
|
||||||
|
|
@ -125,15 +130,15 @@ func TestAddressHexChecksum(t *testing.T) {
|
||||||
Output string
|
Output string
|
||||||
}{
|
}{
|
||||||
// Test cases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md#specification
|
// Test cases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md#specification
|
||||||
{"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"},
|
{"xdc5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", "xdc5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"},
|
||||||
{"0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359", "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"},
|
{"xdcfb6916095ca1df60bb79ce92ce3ea74c37c5d359", "xdcfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"},
|
||||||
{"0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb", "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"},
|
{"xdcdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb", "xdcdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"},
|
||||||
{"0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb", "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"},
|
{"xdcd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb", "xdcD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"},
|
||||||
// Ensure that non-standard length input values are handled correctly
|
// Ensure that non-standard length input values are handled correctly
|
||||||
{"0xa", "0x000000000000000000000000000000000000000A"},
|
{"0xa", "xdc000000000000000000000000000000000000000A"},
|
||||||
{"0x0a", "0x000000000000000000000000000000000000000A"},
|
{"0x0a", "xdc000000000000000000000000000000000000000A"},
|
||||||
{"0x00a", "0x000000000000000000000000000000000000000A"},
|
{"0x00a", "xdc000000000000000000000000000000000000000A"},
|
||||||
{"0x000000000000000000000000000000000000000a", "0x000000000000000000000000000000000000000A"},
|
{"0x000000000000000000000000000000000000000a", "xdc000000000000000000000000000000000000000A"},
|
||||||
}
|
}
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
output := HexToAddress(test.Input).Hex()
|
output := HexToAddress(test.Input).Hex()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue