Correct auto recipient

This commit is contained in:
lash 2025-01-12 19:55:14 +00:00
parent dc4ed4341c
commit 81d2e3e1e9
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -27,7 +27,7 @@ const (
pubKeyLen int = 20 pubKeyLen int = 20
hashLen int = 32 hashLen int = 32
defaultDecimals = 6 defaultDecimals = 6
zeroAccount string = "0x0000000000000000000000000000000000000000" zeroAddress string = "0x0000000000000000000000000000000000000000"
) )
type Tx struct { type Tx struct {
@ -89,7 +89,12 @@ func NewDevAccountService(ctx context.Context, d string) *DevAccountService {
txs: make(map[string]Tx), txs: make(map[string]Tx),
txsTrack: make(map[string]string), txsTrack: make(map[string]string),
autoVoucherValue: make(map[string]int), autoVoucherValue: make(map[string]int),
defaultAccount: zeroAddress,
} }
acc := Account{
Address: zeroAddress,
}
svc.accounts[acc.Address] = acc
err := svc.db.Connect(ctx, d) err := svc.db.Connect(ctx, d)
if err != nil { if err != nil {
panic(err) panic(err)
@ -272,9 +277,12 @@ func (das *DevAccountService) CreateAccount(ctx context.Context) (*models.Accoun
das.accounts[pubKey] = acc das.accounts[pubKey] = acc
das.accountsTrack[uid.String()] = pubKey das.accountsTrack[uid.String()] = pubKey
das.balanceAuto(ctx, pubKey) err = das.balanceAuto(ctx, pubKey)
if err != nil {
return nil, err
}
if das.defaultAccount == zeroAccount { if das.defaultAccount == zeroAddress {
das.defaultAccount = pubKey das.defaultAccount = pubKey
} }
@ -386,7 +394,7 @@ func (das *DevAccountService) TokenTransfer(ctx context.Context, amount, from, t
if !ok { if !ok {
return nil, fmt.Errorf("sender account %v not found", from) return nil, fmt.Errorf("sender account %v not found", from)
} }
accTo, ok := das.accounts[from] accTo, ok := das.accounts[to]
if !ok { if !ok {
if !das.toAutoCreate { if !das.toAutoCreate {
return nil, fmt.Errorf("recipient account %v not found, and not creating", from) return nil, fmt.Errorf("recipient account %v not found, and not creating", from)