1
+ use std:: time:: Duration ;
2
+
3
+ use fuel_core:: {
4
+ database:: Database ,
5
+ chain_config:: { ChainConfig , StateConfig , CoinConfig } ,
6
+ service:: { Config as FuelServiceConfig , FuelService , config:: Trigger } ,
7
+ types::
8
+ fuel_types:: AssetId
9
+
10
+ ,
11
+ } ;
12
+ use fuel_crypto:: fuel_types:: { Address , Bytes32 } ;
13
+
14
+ use fuels:: {
15
+ prelude:: WalletUnlocked ,
16
+ accounts:: { ViewOnlyAccount , provider:: Provider } ,
17
+ } ;
18
+
19
+ use super :: constants:: { N_ACCOUNTS , DEFAULT_MNEMONIC_PHRASE } ;
20
+
21
+ pub async fn bootstrap1 ( ) -> anyhow:: Result < ( FuelService , Provider ) > {
22
+ let mut accounts: Vec < WalletUnlocked > = Vec :: new ( ) ;
23
+
24
+ for index in 0 ..N_ACCOUNTS {
25
+ let wallet =
26
+ WalletUnlocked :: new_from_mnemonic_phrase_with_path (
27
+ DEFAULT_MNEMONIC_PHRASE ,
28
+ None ,
29
+ format ! ( "m/44'/60'/0'/0/{}" , index) . as_str ( )
30
+ ) . expect ( "Could not instantiate account" ) ;
31
+
32
+ accounts. push ( wallet) ;
33
+ }
34
+
35
+ let coins: Vec < CoinConfig > = accounts
36
+ . clone ( )
37
+ . iter ( )
38
+ . enumerate ( )
39
+ . map ( |( index, account) | {
40
+ let asset_id: AssetId = Default :: default ( ) ;
41
+ let amount = 10_000_000 ;
42
+
43
+ let mut vec_tx_id = vec ! [ 0u8 ; 32 ] ;
44
+ vec_tx_id[ 31 ] = index as u8 ;
45
+ let tx_id_slice: & [ u8 ; 32 ] = vec_tx_id. as_slice ( ) . try_into ( ) . expect ( "asd" ) ;
46
+ let tx_id = Bytes32 :: from_bytes_ref ( tx_id_slice) . clone ( ) ;
47
+
48
+ CoinConfig {
49
+ tx_id : Some ( tx_id) ,
50
+ output_index : Some ( 0 ) ,
51
+ tx_pointer_block_height : Some ( 0 . into ( ) ) ,
52
+ tx_pointer_tx_idx : Some ( 0 ) ,
53
+ maturity : Some ( 0 . into ( ) ) ,
54
+ owner : Address :: new ( * account. address ( ) . clone ( ) . hash ) ,
55
+ amount,
56
+ asset_id,
57
+ }
58
+ }
59
+ ) . collect ( ) ;
60
+
61
+ let mut fuel_service_config = FuelServiceConfig {
62
+ chain_conf : ChainConfig {
63
+ initial_state : Some ( StateConfig {
64
+ coins : Some ( coins) ,
65
+ height : Some ( ( 0 ) . into ( ) ) ,
66
+ ..Default :: default ( )
67
+ } ) ,
68
+ ..ChainConfig :: local_testnet ( )
69
+ } ,
70
+ block_production : Trigger :: Interval { block_time : Duration :: from_secs ( 1 ) } ,
71
+ ..FuelServiceConfig :: local_node ( )
72
+ } ;
73
+ fuel_service_config. txpool . min_gas_price = 1 ;
74
+
75
+ let database = Database :: in_memory ( ) ;
76
+
77
+ let srv = FuelService :: from_database ( database. clone ( ) , fuel_service_config. clone ( ) ) . await . unwrap ( ) ;
78
+ srv. await_relayer_synced ( ) . await . unwrap ( ) ;
79
+ let provider = Provider :: connect ( srv. bound_address . to_string ( ) ) . await . unwrap ( ) ;
80
+
81
+ anyhow:: Ok ( ( srv, provider) )
82
+ }
83
+
0 commit comments