-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f9806a
commit 856cec4
Showing
4 changed files
with
138 additions
and
59 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
txn "github.com/humblenginr/btc-miner/transaction" | ||
) | ||
|
||
|
||
|
||
func SelectTransactionsFromPaths(validTxnPaths []string) []*txn.Transaction { | ||
txnSlice := make([]*txn.Transaction, 0) | ||
|
||
for _, fileName := range validTxnPaths { | ||
var transaction txn.Transaction | ||
txnPath := fmt.Sprintf("%s/%s", MempoolDirPath, fileName) | ||
byteResult, _ := os.ReadFile(txnPath) | ||
json.Unmarshal(byteResult, &transaction) | ||
txnSlice = append(txnSlice, &transaction) | ||
} | ||
return txnSlice | ||
} | ||
|
||
func SelectTransactionsFromFolder(validTxnsFolderPath string) []*txn.Transaction { | ||
files, err := os.ReadDir(validTxnsFolderPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
txnSlice := make([]*txn.Transaction, 0) | ||
|
||
for _, f := range files { | ||
var transaction txn.Transaction | ||
txnPath := fmt.Sprintf("%s/%s", validTxnsFolderPath, f.Name()) | ||
byteResult, _ := os.ReadFile(txnPath) | ||
err = json.Unmarshal(byteResult, &transaction) | ||
txnSlice = append(txnSlice, &transaction) | ||
} | ||
return txnSlice | ||
} |
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