Skip to content
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

Add support for v2 transactions to Single Address Wallet #54

Merged
merged 8 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions chain/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package chain

import (
"fmt"
"reflect"
"testing"

Expand Down Expand Up @@ -94,7 +93,6 @@ func TestManager(t *testing.T) {
path = nil
for _, ru := range rus {
path = append(path, ru.State.Index.Height)
fmt.Println(path)
}
for _, au := range aus {
path = append(path, au.State.Index.Height)
Expand Down
6 changes: 1 addition & 5 deletions testutil/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ func (et *ephemeralWalletUpdateTxn) UpdateStateElements(elements []types.StateEl
return nil
}

func (et *ephemeralWalletUpdateTxn) AddEvents(events []wallet.Event) error {
et.store.events = append(events, et.store.events...)
return nil
}

func (et *ephemeralWalletUpdateTxn) ApplyIndex(index types.ChainIndex, created, spent []types.SiacoinElement, events []wallet.Event) error {
for _, se := range spent {
if _, ok := et.store.utxos[types.SiacoinOutputID(se.ID)]; !ok {
Expand Down Expand Up @@ -137,6 +132,7 @@ func (es *EphemeralWalletStore) UnspentSiacoinElements() (utxos []types.SiacoinE
defer es.mu.Unlock()

for _, se := range es.utxos {
se.MerkleProof = append([]types.Hash256(nil), se.MerkleProof...)
utxos = append(utxos, se)
}
return utxos, nil
Expand Down
81 changes: 81 additions & 0 deletions wallet/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package wallet

import (
"time"

"go.sia.tech/core/types"
)

// event types indicate the source of an event. Events can
// either be created by sending Siacoins between addresses or they can be
// created by consensus (e.g. a miner payout, a siafund claim, or a contract).
const (
EventTypeMinerPayout = "miner"
EventTypeFoundationSubsidy = "foundation"

EventTypeV1Transaction = "v1Transaction"
EventTypeV1Contract = "v1Contract"

EventTypeV2Transaction = "v2Transaction"
EventTypeV2Contract = "v2Contract"
)

type (
// An EventMinerPayout represents a miner payout from a block.
EventMinerPayout struct {
SiacoinElement types.SiacoinElement `json:"siacoinElement"`
}

// EventFoundationSubsidy represents a foundation subsidy from a block.
EventFoundationSubsidy struct {
SiacoinElement types.SiacoinElement `json:"siacoinElement"`
}

// An EventV1ContractPayout represents a file contract payout from a v1
// contract.
EventV1ContractPayout struct {
FileContract types.FileContractElement `json:"fileContract"`
SiacoinElement types.SiacoinElement `json:"siacoinElement"`
Missed bool `json:"missed"`
}

// An EventV2ContractPayout represents a file contract payout from a v2
// contract.
EventV2ContractPayout struct {
FileContract types.V2FileContractElement `json:"fileContract"`
Resolution types.V2FileContractResolutionType `json:"resolution"`
SiacoinElement types.SiacoinElement `json:"siacoinElement"`
Missed bool `json:"missed"`
}

// EventV1Transaction is a transaction event that includes the transaction
EventV1Transaction types.Transaction

// EventV2Transaction is a transaction event that includes the transaction
EventV2Transaction types.V2Transaction

// EventData contains the data associated with an event.
EventData interface {
isEvent() bool
}

// An Event is a transaction or other event that affects the wallet including
// miner payouts, siafund claims, and file contract payouts.
Event struct {
ID types.Hash256 `json:"id"`
Index types.ChainIndex `json:"index"`
Inflow types.Currency `json:"inflow"`
Outflow types.Currency `json:"outflow"`
Type string `json:"type"`
Data EventData `json:"data"`
MaturityHeight uint64 `json:"maturityHeight"`
Timestamp time.Time `json:"timestamp"`
}
)

func (EventMinerPayout) isEvent() bool { return true }
func (EventFoundationSubsidy) isEvent() bool { return true }
func (EventV1ContractPayout) isEvent() bool { return true }
func (EventV2ContractPayout) isEvent() bool { return true }
func (EventV1Transaction) isEvent() bool { return true }
func (EventV2Transaction) isEvent() bool { return true }
Loading
Loading