-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (65 loc) · 2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package stress
import (
"math/big"
"sync"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stellar/go/clients/horizon"
"github.com/stellar/go/support/log"
)
const satsInBtc = 100000000
var (
ten = big.NewInt(10)
eighteen = big.NewInt(18)
// weiInEth = 10^18
weiInEth = new(big.Int).Exp(ten, eighteen, nil)
)
// RandomBitcoinClient implements bitcoin.Client and generates random bitcoin transactions.
type RandomBitcoinClient struct {
currentBlockNumber int64
heightHash map[int64]*chainhash.Hash
hashBlock map[*chainhash.Hash]*wire.MsgBlock
userAddresses []string
userAddressesLock sync.Mutex
firstBlockGenerated chan bool
log *log.Entry
}
// RandomEthereumClient implements ethereum.Client and generates random ethereum transactions.
type RandomEthereumClient struct {
currentBlockNumber int64
blocks map[int64]*types.Block
userAddresses []string
userAddressesLock sync.Mutex
firstBlockGenerated chan bool
log *log.Entry
}
type UserState int
const (
PendingUserState UserState = iota
GeneratedAddressUserState
AccountCreatedUserState
TrustLinesCreatedUserState
ReceivedPaymentUserState
)
// Users is responsible for imitating user interactions:
// * Request a new bifrost address by calling /generate-bitcoin-address or /generate-ethereum-address.
// * Add a generate address to RandomBitcoinClient or RandomEthereumClient so it generates a new transaction
// and puts it in a future block.
// * Once account is funded, create a trustline.
// * Wait for BTC/ETH payment.
type Users struct {
Horizon horizon.ClientInterface
NetworkPassphrase string
UsersPerSecond int
BifrostPorts []int
IssuerPublicKey string
users map[string]*User // public key => User
usersLock sync.Mutex
log *log.Entry
}
type User struct {
State UserState
AccountCreated chan bool
PaymentReceived chan bool
}