@@ -36,23 +36,15 @@ defmodule DB.Chain do
3636 end
3737
3838 def pop ( pk , db_opts \\ % { } ) do
39- RocksDB . get ( "bic:epoch:pop: #{ pk } " , db_handle ( db_opts , :contractstate , % { } ) )
39+ RocksDB . get ( "account: #{ pk } :attribute:pop " , db_handle ( db_opts , :contractstate , % { } ) )
4040 end
4141
4242 def nonce ( pk , db_opts \\ % { } ) do
43- if RocksDB . exists ( "account:#{ pk } :attribute:nonce" , db_handle ( db_opts , :contractstate , % { to_integer: true } ) ) do
44- RocksDB . get ( "account:#{ pk } :attribute:nonce" , db_handle ( db_opts , :contractstate , % { to_integer: true } ) )
45- else
46- RocksDB . get ( "bic:base:nonce:#{ pk } " , db_handle ( db_opts , :contractstate , % { to_integer: true } ) )
47- end
43+ RocksDB . get ( "account:#{ pk } :attribute:nonce" , db_handle ( db_opts , :contractstate , % { to_integer: true } ) )
4844 end
4945
5046 def balance ( pk , symbol \\ "AMA" , db_opts \\ % { } ) do
51- if RocksDB . exists ( "account:#{ pk } :balance:#{ symbol } " , db_handle ( db_opts , :contractstate , % { to_integer: true } ) ) do
52- RocksDB . get ( "account:#{ pk } :balance:#{ symbol } " , db_handle ( db_opts , :contractstate , % { to_integer: true } ) ) || 0
53- else
54- RocksDB . get ( "bic:coin:balance:#{ pk } :#{ symbol } " , db_handle ( db_opts , :contractstate , % { to_integer: true } ) ) || 0
55- end
47+ RocksDB . get ( "account:#{ pk } :balance:#{ symbol } " , db_handle ( db_opts , :contractstate , % { to_integer: true } ) ) || 0
5648 end
5749
5850 def tx ( tx_hash , db_opts \\ % { } ) do
@@ -79,23 +71,20 @@ defmodule DB.Chain do
7971 end
8072
8173 def validators_for_height ( height , db_opts \\ % { } ) do
82- opts = db_handle ( db_opts , :contractstate , % { term: true } )
74+ opts = db_handle ( db_opts , :contractstate , % { } )
8375 cond do
84- height in 3195570 .. 3195575 ->
85- RocksDB . get ( "bic:epoch:validators:height:000000319557" , opts )
86- true ->
87- case RocksDB . get_prev_or_first ( "bic:epoch:validators:height:" , pad_integer ( height ) , db_handle ( db_opts , :contractstate , % { } ) ) do
88- { nil , nil } ->
89- { _ , value } = RocksDB . get_prev_or_first ( "bic:epoch:trainers:height:" , pad_integer ( height ) , opts )
90- value
91- { _ , value } -> RDB . vecpak_decode ( value )
92- end
76+ height in 3195570 .. 3195575 ->
77+ RocksDB . get ( "bic:epoch:validators:height:000000319557" , opts )
78+ |> RDB . vecpak_decode ( )
79+ true ->
80+ { _ , value } = RocksDB . get_prev_or_first ( "bic:epoch:validators:height:" , pad_integer ( height ) , opts )
81+ RDB . vecpak_decode ( value )
9382 end
9483 end
9584
9685 def validators_last_change_height ( height , db_opts \\ % { } ) do
97- opts = db_handle ( db_opts , :contractstate , % { term: true } )
98- { key , _value } = RocksDB . get_prev_or_first ( "bic:epoch:trainers :height:" , pad_integer ( height ) , opts )
86+ opts = db_handle ( db_opts , :contractstate , % { } )
87+ { key , _value } = RocksDB . get_prev_or_first ( "bic:epoch:validators :height:" , pad_integer ( height ) , opts )
9988 :erlang . binary_to_integer ( key )
10089 end
10190
0 commit comments