Skip to content

Commit 3010197

Browse files
committed
Merge branch 'master' into indexer
2 parents 4576949 + 5ab17a7 commit 3010197

File tree

12 files changed

+84
-36
lines changed

12 files changed

+84
-36
lines changed

pkg/client-sdk/client.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,31 @@ func (a *arkClient) GetConfigData(
7474
}
7575

7676
func (a *arkClient) Unlock(ctx context.Context, pasword string) error {
77+
if a.wallet == nil {
78+
return fmt.Errorf("wallet not initialized")
79+
}
7780
_, err := a.wallet.Unlock(ctx, pasword)
7881
return err
7982
}
8083

8184
func (a *arkClient) Lock(ctx context.Context) error {
85+
if a.wallet == nil {
86+
return fmt.Errorf("wallet not initialized")
87+
}
8288
return a.wallet.Lock(ctx)
8389
}
8490

8591
func (a *arkClient) IsLocked(ctx context.Context) bool {
92+
if a.wallet == nil {
93+
return true
94+
}
8695
return a.wallet.IsLocked()
8796
}
8897

8998
func (a *arkClient) Dump(ctx context.Context) (string, error) {
99+
if err := a.safeCheck(); err != nil {
100+
return "", err
101+
}
90102
return a.wallet.Dump(ctx)
91103
}
92104

@@ -100,14 +112,23 @@ func (a *arkClient) Receive(ctx context.Context) (string, string, error) {
100112
}
101113

102114
func (a *arkClient) GetTransactionEventChannel(_ context.Context) chan types.TransactionEvent {
103-
return a.store.TransactionStore().GetEventChannel()
115+
if a.store != nil && a.store.TransactionStore() != nil {
116+
return a.store.TransactionStore().GetEventChannel()
117+
}
118+
return nil
104119
}
105120

106121
func (a *arkClient) GetVtxoEventChannel(_ context.Context) chan types.VtxoEvent {
107-
return a.store.VtxoStore().GetEventChannel()
122+
if a.store != nil && a.store.VtxoStore() != nil {
123+
return a.store.VtxoStore().GetEventChannel()
124+
}
125+
return nil
108126
}
109127

110128
func (a *arkClient) SignTransaction(ctx context.Context, tx string) (string, error) {
129+
if err := a.safeCheck(); err != nil {
130+
return "", err
131+
}
111132
return a.wallet.SignTransaction(ctx, a.explorer, tx)
112133
}
113134

@@ -119,7 +140,7 @@ func (a *arkClient) Reset(ctx context.Context) {
119140
}
120141

121142
func (a *arkClient) Stop() error {
122-
if a.Config.WithTransactionFeed {
143+
if a.txStreamCtxCancel != nil {
123144
a.txStreamCtxCancel()
124145
}
125146

@@ -234,6 +255,7 @@ func (a *arkClient) initWithWallet(
234255
MarketHourEndTime: info.MarketHourEndTime,
235256
MarketHourPeriod: info.MarketHourPeriod,
236257
MarketHourRoundInterval: info.MarketHourRoundInterval,
258+
ExplorerURL: explorerSvc.BaseUrl(),
237259
}
238260
if err := a.store.ConfigStore().AddData(ctx, storeData); err != nil {
239261
return err
@@ -309,7 +331,7 @@ func (a *arkClient) init(
309331
UnilateralExitDelay: common.RelativeLocktime{Type: unilateralExitDelayType, Value: uint32(info.UnilateralExitDelay)},
310332
Dust: info.Dust,
311333
BoardingDescriptorTemplate: info.BoardingDescriptorTemplate,
312-
ExplorerURL: args.ExplorerURL,
334+
ExplorerURL: explorerSvc.BaseUrl(),
313335
ForfeitAddress: info.ForfeitAddress,
314336
WithTransactionFeed: args.WithTransactionFeed,
315337
MarketHourStartTime: info.MarketHourStartTime,

server/Makefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ lint:
3636
@echo "Linting code..."
3737
@golangci-lint run --fix
3838

39-
## run: run in regtest mode with bitcoind
39+
## run: run arkd in dev mode with bitcoind on regtest
4040
run: clean
41-
@echo "Running arkd with Bitcoin Core in regtest mode ..."
41+
@echo "Running arkd with Bitcoin Core in dev mode on regtest ..."
4242
$(call setup_env, envs/bitcoind.regtest.env)
43-
4443
go run ./cmd/arkd
4544

46-
## run-neutrino: run in regtest mode with neutrino
45+
## run-neutrino: run arkd in dev mode with neutrino on regtest
4746
run-neutrino: clean
48-
@echo "Running arkd with Neutrino in regtest mode ..."
47+
@echo "Running arkd with Neutrino in dev mode on regtest ..."
4948
$(call setup_env, envs/neutrino.regtest.env)
5049
go run ./cmd/arkd
5150

52-
## run-neutrino-mutinynet: run in signet mode
51+
## run-neutrino-mutinynet: run arkd in dev mode with neutrino on mutinynet
5352
run-neutrino-mutinynet: clean
54-
@echo "Running arkd with Neutrino in signet mode ..."
55-
$(call setup_env, envs/neutrino.signet.env)
53+
@echo "Running arkd with Neutrino in dev mode on mutinynet ..."
54+
$(call setup_env, envs/neutrino.mutinynet.env)
5655
go run ./cmd/arkd
5756

5857
## test: runs unit and component tests

server/envs/bitcoind.regtest.env

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
ARK_ROUND_INTERVAL=10
21
ARK_LOG_LEVEL=5
32
ARK_NETWORK=regtest
4-
ARK_PORT=7070
5-
ARK_NO_TLS=true
63
ARK_NO_MACAROONS=true
7-
ARK_TX_BUILDER_TYPE=covenantless
84
ARK_BITCOIND_RPC_USER=admin1
95
ARK_BITCOIND_RPC_PASS=123
106
ARK_BITCOIND_RPC_HOST=localhost:18443
117
ARK_BITCOIND_ZMQ_BLOCK=tcp://127.0.0.1:28332
128
ARK_BITCOIND_ZMQ_TX=tcp://127.0.0.1:28333
13-
ARK_DATADIR=./data/regtest
9+
ARK_DATADIR=./data/regtest
10+
ARK_VTXO_TREE_EXPIRY= 604672
11+
ARK_UNILATERAL_EXIT_DELAY = 1024
12+
ARK_BOARDING_EXIT_DELAY = 604672
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
ARK_ROUND_INTERVAL=10
21
ARK_LOG_LEVEL=5
32
ARK_NETWORK=mutinynet
4-
ARK_PORT=7070
5-
ARK_NO_TLS=true
63
ARK_NO_MACAROONS=true
7-
ARK_TX_BUILDER_TYPE=covenantless
84
ARK_ESPLORA_URL=https://mutinynet.com/api
95
ARK_NEUTRINO_PEER=45.79.52.207:38333
10-
ARK_DATADIR=./data/mutinynet
6+
ARK_DATADIR=./data/mutinynet
7+
ARK_VTXO_TREE_EXPIRY= 604672
8+
ARK_UNILATERAL_EXIT_DELAY = 1024
9+
ARK_BOARDING_EXIT_DELAY = 604672

server/envs/neutrino.regtest.env

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
ARK_ROUND_INTERVAL=10
21
ARK_LOG_LEVEL=5
32
ARK_NETWORK=regtest
4-
ARK_PORT=7070
5-
ARK_NO_TLS=true
63
ARK_NO_MACAROONS=true
7-
ARK_TX_BUILDER_TYPE=covenantless
84
ARK_ESPLORA_URL=http://localhost:3000
95
ARK_NEUTRINO_PEER=localhost:18444
106
ARK_DATADIR=./data/regtest
11-
ARK_ALLOW_ZERO_FEES=true
7+
ARK_ALLOW_ZERO_FEES=true
8+
ARK_VTXO_TREE_EXPIRY= 604672
9+
ARK_UNILATERAL_EXIT_DELAY = 1024
10+
ARK_BOARDING_EXIT_DELAY = 604672

server/internal/config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,24 @@ var (
166166
VtxoMinAmount = "VTXO_MIN_AMOUNT"
167167

168168
defaultDatadir = common.AppDataDir("arkd", false)
169-
defaultRoundInterval = 15
169+
defaultRoundInterval = 30
170170
DefaultPort = 7070
171171
defaultDbType = "sqlite"
172172
defaultEventDbType = "badger"
173173
defaultSchedulerType = "gocron"
174174
defaultTxBuilderType = "covenantless"
175175
defaultNetwork = "bitcoin"
176176
defaultEsploraURL = "https://blockstream.info/api"
177-
defaultLogLevel = 5
178-
defaultVtxoTreeExpiry = 604672
179-
defaultUnilateralExitDelay = 1024
180-
defaultBoardingExitDelay = 604672
177+
defaultLogLevel = 4
178+
defaultVtxoTreeExpiry = 604672 // 7 days
179+
defaultUnilateralExitDelay = 86400 // 24 hours
180+
defaultBoardingExitDelay = 7776000 // 3 months
181181
defaultNoMacaroons = false
182182
defaultNoTLS = true
183183
defaultNostrDefaultRelays = []string{"wss://relay.primal.net", "wss://relay.damus.io"}
184184
defaultMarketHourStartTime = time.Now()
185-
defaultMarketHourEndTime = defaultMarketHourStartTime.Add(time.Duration(defaultRoundInterval) * time.Second)
186-
defaultMarketHourPeriod = time.Duration(24) * time.Hour
185+
defaultMarketHourEndTime = defaultMarketHourStartTime.Add(time.Hour)
186+
defaultMarketHourPeriod = 24 * time.Hour
187187
defaultMarketHourInterval = time.Duration(defaultRoundInterval) * time.Second
188188

189189
defaultAllowZeroFees = false

server/internal/core/application/covenantless.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,9 @@ func (s *covenantlessService) getNewVtxos(round *domain.Round) []domain.Vtxo {
19171917
return nil
19181918
}
19191919

1920-
createdAt := time.Now().Unix()
1920+
now := time.Now()
1921+
createdAt := now.Unix()
1922+
expireAt := now.Add(time.Duration(s.vtxoTreeExpiry.Seconds()) * time.Second).Unix()
19211923

19221924
leaves := round.VtxoTree.Leaves()
19231925
vtxos := make([]domain.Vtxo, 0)
@@ -1941,6 +1943,7 @@ func (s *covenantlessService) getNewVtxos(round *domain.Round) []domain.Vtxo {
19411943
Amount: uint64(out.Value),
19421944
RoundTxid: round.Txid,
19431945
CreatedAt: createdAt,
1946+
ExpireAt: expireAt,
19441947
})
19451948
}
19461949
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP INDEX IF EXISTS idx_round_txid;
2+
3+
CREATE UNIQUE INDEX IF NOT EXISTS idx_round_txid ON round(txid);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP INDEX IF EXISTS idx_round_txid;
2+
3+
CREATE INDEX IF NOT EXISTS idx_round_txid ON round(txid);

server/internal/infrastructure/wallet/btc-embedded/esplora.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (f *esploraClient) broadcast(txhex string) error {
4545
return err
4646
}
4747

48-
if strings.Contains(strings.ToLower(string(content)), "non-BIP68-final") {
48+
if strings.Contains(strings.ToLower(string(content)), "non-bip68-final") {
4949
return ports.ErrNonFinalBIP68
5050
}
5151

server/internal/interface/grpc/permissions/permissions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ func Whitelist() map[string][]bakery.Op {
162162
Entity: EntityArk,
163163
Action: "write",
164164
}},
165+
fmt.Sprintf("/%s/GetTransactionsStream", arkv1.ArkService_ServiceDesc.ServiceName): {{
166+
Entity: EntityArk,
167+
Action: "read",
168+
}},
165169
fmt.Sprintf("/%s/GetRound", arkv1.ExplorerService_ServiceDesc.ServiceName): {{
166170
Entity: EntityExplorer,
167171
Action: "read",
@@ -174,6 +178,10 @@ func Whitelist() map[string][]bakery.Op {
174178
Entity: EntityExplorer,
175179
Action: "read",
176180
}},
181+
fmt.Sprintf("/%s/SubscribeForAddress", arkv1.ExplorerService_ServiceDesc.ServiceName): {{
182+
Entity: EntityExplorer,
183+
Action: "read",
184+
}},
177185
}
178186
}
179187

server/internal/interface/grpc/permissions/permissions_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,28 @@ func TestRestrictedMethods(t *testing.T) {
3030

3131
func TestWhitelistedMethods(t *testing.T) {
3232
allMethods := make([]string, 0)
33+
3334
for _, m := range arkv1.ArkService_ServiceDesc.Methods {
3435
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.ArkService_ServiceDesc.ServiceName, m.MethodName))
3536
}
37+
for _, m := range arkv1.ArkService_ServiceDesc.Streams {
38+
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.ArkService_ServiceDesc.ServiceName, m.StreamName))
39+
}
40+
3641
for _, v := range arkv1.WalletInitializerService_ServiceDesc.Methods {
3742
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.WalletInitializerService_ServiceDesc.ServiceName, v.MethodName))
3843
}
44+
for _, m := range arkv1.WalletInitializerService_ServiceDesc.Streams {
45+
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.WalletInitializerService_ServiceDesc.ServiceName, m.StreamName))
46+
}
47+
3948
for _, m := range arkv1.ExplorerService_ServiceDesc.Methods {
4049
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.ExplorerService_ServiceDesc.ServiceName, m.MethodName))
4150
}
51+
for _, m := range arkv1.ExplorerService_ServiceDesc.Streams {
52+
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.ExplorerService_ServiceDesc.ServiceName, m.StreamName))
53+
}
54+
4255
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", grpchealth.Health_ServiceDesc.ServiceName, "Check"))
4356

4457
whitelist := permissions.Whitelist()

0 commit comments

Comments
 (0)