-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK - Tx Storage & Ark SDK func update #320
Open
sekulicd
wants to merge
12
commits into
ark-network:master
Choose a base branch
from
sekulicd:SDK-Covenant-GetTxHistory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7b409f5
empty config check & version flag support
sekulicd f787e19
fix: empty config check & version flag support (#309)
sekulicd 53618f0
fix
sekulicd e78e35f
merge
sekulicd fb7b33f
Merge pull request #310 from sekulicd/CLI-fix-config
sekulicd b20227e
Merge remote-tracking branch 'upstream/master'
sekulicd 1f1a62f
Merge remote-tracking branch 'upstream/master'
sekulicd 5acf6ed
test vtxosToTxsCovenant
sekulicd ab21a33
Implement background VTXO syncing and database insertion
sekulicd 120a562
fix
sekulicd 7c87b37
Merge remote-tracking branch 'upstream/master'
sekulicd c82ddfc
merge with master
sekulicd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
filestore "github.com/ark-network/ark/pkg/client-sdk/wallet/singlekey/store/file" | ||
inmemorystore "github.com/ark-network/ark/pkg/client-sdk/wallet/singlekey/store/inmemory" | ||
"github.com/decred/dcrd/dcrec/secp256k1/v4" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
|
@@ -51,12 +52,23 @@ var ( | |
} | ||
) | ||
|
||
const ( | ||
vtxoSpent spent = true | ||
vtxoUnspent spent = false | ||
) | ||
|
||
type spent bool | ||
|
||
type arkClient struct { | ||
*store.StoreData | ||
wallet wallet.WalletService | ||
store store.ConfigStore | ||
explorer explorer.Explorer | ||
client client.ASPClient | ||
wallet wallet.WalletService | ||
store store.ConfigStore | ||
appDataStore store.AppDataStore | ||
explorer explorer.Explorer | ||
client client.ASPClient | ||
|
||
vtxosChan chan map[spent]client.Vtxo | ||
vtxoListeningStarted bool | ||
} | ||
|
||
func (a *arkClient) GetConfigData( | ||
|
@@ -130,9 +142,77 @@ func (a *arkClient) InitWithWallet( | |
a.explorer = explorerSvc | ||
a.client = clientSvc | ||
|
||
a.vtxosChan = make(chan map[spent]client.Vtxo) | ||
a.listenForVtxos(ctx, a.vtxosChan) | ||
|
||
return nil | ||
} | ||
|
||
func (a *arkClient) GetTransactionHistory( | ||
ctx context.Context, | ||
) ([]store.Transaction, error) { | ||
return a.appDataStore.TransactionRepository().GetAll(ctx) | ||
} | ||
|
||
func (a *arkClient) ListVtxos( | ||
ctx context.Context, | ||
) (spendableVtxos, spentVtxos []client.Vtxo, err error) { | ||
offchainAddrs, _, _, err := a.wallet.GetAddresses(ctx) | ||
if err != nil { | ||
return | ||
} | ||
|
||
for _, addr := range offchainAddrs { | ||
spendable, spent, err := a.client.ListVtxos(ctx, addr) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
spendableVtxos = append(spendableVtxos, spendable...) | ||
spentVtxos = append(spentVtxos, spent...) | ||
} | ||
|
||
return | ||
} | ||
Comment on lines
+157
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after syncing with master this must be dropped |
||
|
||
func (a *arkClient) listenForVtxos( | ||
ctx context.Context, | ||
vtxoChan chan<- map[spent]client.Vtxo, | ||
) { | ||
go func() { | ||
ticker := time.NewTicker(1 * time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-ticker.C: | ||
spendableVtxos, spentVtxos, err := a.ListVtxos(ctx) | ||
if err != nil { | ||
log.Warnf("listenForNewVtxos: failed to list vtxos: %s", err) | ||
continue | ||
} | ||
|
||
allVtxos := make(map[spent]client.Vtxo) | ||
for _, vtxo := range spendableVtxos { | ||
allVtxos[vtxoUnspent] = vtxo | ||
} | ||
for _, vtxo := range spentVtxos { | ||
allVtxos[vtxoSpent] = vtxo | ||
} | ||
|
||
go func() { | ||
if len(allVtxos) > 0 { | ||
vtxoChan <- allVtxos | ||
} | ||
}() | ||
} | ||
} | ||
}() | ||
|
||
a.vtxoListeningStarted = true | ||
} | ||
|
||
func (a *arkClient) Init( | ||
ctx context.Context, args InitArgs, | ||
) error { | ||
|
@@ -201,6 +281,9 @@ func (a *arkClient) Init( | |
a.explorer = explorerSvc | ||
a.client = clientSvc | ||
|
||
a.vtxosChan = make(chan map[spent]client.Vtxo) | ||
a.listenForVtxos(ctx, a.vtxosChan) | ||
|
||
return nil | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why
map[spent]client.Vtxo
?