Execute transactions in go routines concurrently

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
This commit is contained in:
Stanislav Jakuschevskij 2025-01-03 17:45:02 +01:00
parent 81efd2cc61
commit dfd860d8e9
No known key found for this signature in database
GPG key ID: 78195D2E6998E2EB

View file

@ -2,6 +2,7 @@ package main
import (
"fmt"
"sync"
atb "offChainData/contract"
"offChainData/utils"
@ -35,16 +36,23 @@ func newTransactApp(smartContract *atb.AssetTransferBasic) *transactApp {
}
func (t *transactApp) run() {
var wg sync.WaitGroup
for i := 0; i < t.batchSize; i++ {
t.transact()
wg.Add(1)
go func() {
defer wg.Done()
t.transact()
}()
}
wg.Wait()
}
func (t *transactApp) transact() {
anAsset := atb.NewAsset()
t.smartContract.CreateAsset(anAsset)
// TODO print txID to compare easier with block processing
fmt.Println("Created asset", anAsset.ID)
// Transfer randomly 1 in 2 assets to a new owner.