@@ -8,7 +8,6 @@ use crate::{
8
8
use move_core_types:: account_address:: AccountAddress ;
9
9
use move_ir_types:: location:: * ;
10
10
use move_symbol_pool:: Symbol ;
11
- use num_bigint:: BigUint ;
12
11
use petgraph:: { algo:: astar as petgraph_astar, graphmap:: DiGraphMap } ;
13
12
use std:: {
14
13
collections:: BTreeMap ,
@@ -62,25 +61,6 @@ pub fn parse_u128(s: &str) -> Result<(u128, NumberFormat), ParseIntError> {
62
61
Ok ( ( u128:: from_str_radix ( txt, base as u32 ) ?, base) )
63
62
}
64
63
65
- // Parse an address from a decimal or hex encoding
66
- pub fn parse_address ( s : & str ) -> Option < ( [ u8 ; AccountAddress :: LENGTH ] , NumberFormat ) > {
67
- let ( txt, base) = determine_num_text_and_base ( s) ;
68
- let parsed = BigUint :: parse_bytes (
69
- txt. as_bytes ( ) ,
70
- match base {
71
- NumberFormat :: Hex => 16 ,
72
- NumberFormat :: Decimal => 10 ,
73
- } ,
74
- ) ?;
75
- let bytes = parsed. to_bytes_be ( ) ;
76
- if bytes. len ( ) > AccountAddress :: LENGTH {
77
- return None ;
78
- }
79
- let mut result = [ 0u8 ; AccountAddress :: LENGTH ] ;
80
- result[ ( AccountAddress :: LENGTH - bytes. len ( ) ) ..] . clone_from_slice ( & bytes) ;
81
- Some ( ( result, base) )
82
- }
83
-
84
64
//**************************************************************************************************
85
65
// Address
86
66
//**************************************************************************************************
@@ -98,7 +78,9 @@ pub struct NumericalAddress {
98
78
impl NumericalAddress {
99
79
// bytes used for errors when an address is not known but is needed
100
80
pub const DEFAULT_ERROR_ADDRESS : Self = NumericalAddress {
101
- bytes : AccountAddress :: ONE ,
81
+ bytes : AccountAddress :: new ( [
82
+ 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 1u8 ,
83
+ ] ) ,
102
84
format : NumberFormat :: Hex ,
103
85
} ;
104
86
@@ -118,22 +100,22 @@ impl NumericalAddress {
118
100
}
119
101
120
102
pub fn parse_str ( s : & str ) -> Result < NumericalAddress , String > {
121
- match parse_address ( s) {
122
- Some ( ( n, format) ) => Ok ( NumericalAddress {
123
- bytes : AccountAddress :: new ( n) ,
124
- format,
125
- } ) ,
126
- None =>
127
- // TODO the kind of error is in an unstable nightly API
128
- // But currently the only way this should fail is if the number is too long
129
- {
130
- Err ( format ! (
103
+ let ( n, format) = match parse_u128 ( s) {
104
+ Ok ( res) => res,
105
+ Err ( _) => {
106
+ // TODO the kind of error is in an unstable nightly API
107
+ // But currently the only way this should fail is if the number is too long
108
+ return Err (
131
109
"Invalid address literal. The numeric value is too large. The maximum size is \
132
- {} bytes",
133
- AccountAddress :: LENGTH
134
- ) )
110
+ 16 bytes"
111
+ . to_owned ( ) ,
112
+ ) ;
135
113
}
136
- }
114
+ } ;
115
+ Ok ( NumericalAddress {
116
+ bytes : AccountAddress :: new ( n. to_be_bytes ( ) ) ,
117
+ format,
118
+ } )
137
119
}
138
120
}
139
121
@@ -147,7 +129,7 @@ impl fmt::Display for NumericalAddress {
147
129
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
148
130
match self . format {
149
131
NumberFormat :: Decimal => {
150
- let n = BigUint :: from_bytes_be ( self . bytes . as_ref ( ) ) ;
132
+ let n = u128 :: from_be_bytes ( self . bytes . into_bytes ( ) ) ;
151
133
write ! ( f, "{}" , n)
152
134
}
153
135
NumberFormat :: Hex => write ! ( f, "{:#X}" , self ) ,
0 commit comments