-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
10 changed files
with
183 additions
and
22 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
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 |
---|---|---|
@@ -1,19 +1,58 @@ | ||
package models | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"encoding/binary" | ||
"encoding/hex" | ||
"fmt" | ||
|
||
// AlertMessageConfiscateUtxo is a confiscate utxo alert | ||
type AlertMessageConfiscateUtxo struct { | ||
"github.com/libsv/go-bn/models" | ||
) | ||
|
||
// AlertMessageConfiscateTransaction is a confiscate utxo alert | ||
type AlertMessageConfiscateTransaction struct { | ||
AlertMessage | ||
// TODO finish building out this alert type | ||
Transactions []models.ConfiscationTransactionDetails | ||
} | ||
|
||
type ConfiscateTransaction struct { | ||
EnforceAtHeight [8]byte | ||
Id [32]byte | ||
} | ||
|
||
// Read reads the alert | ||
func (a *AlertMessageConfiscateUtxo) Read(_ []byte) error { | ||
func (a *AlertMessageConfiscateTransaction) Read(raw []byte) error { | ||
a.Config().Services.Log.Infof("%x", raw) | ||
if len(raw) < 40 { | ||
return fmt.Errorf("confiscation alert is less than 41 bytes") | ||
} | ||
if len(raw)%40 != 0 { | ||
return fmt.Errorf("confiscation alert is not a multiple of 41 bytes") | ||
} | ||
txCount := len(raw) / 40 | ||
details := []models.ConfiscationTransactionDetails{} | ||
for i := 0; i < txCount; i++ { | ||
tx := ConfiscateTransaction{ | ||
EnforceAtHeight: [8]byte(raw[:8]), | ||
Id: [32]byte(raw[8:40]), | ||
} | ||
detail := models.ConfiscationTransactionDetails{ | ||
ConfiscationTransaction: models.ConfiscationTransaction{ | ||
EnforceAtHeight: int64(binary.LittleEndian.Uint64(tx.EnforceAtHeight[:])), | ||
Hex: hex.EncodeToString(tx.Id[:]), | ||
}, | ||
} | ||
details = append(details, detail) | ||
raw = raw[40:] | ||
} | ||
return nil | ||
} | ||
|
||
// Do executes the alert | ||
func (a *AlertMessageConfiscateUtxo) Do(_ context.Context) error { | ||
func (a *AlertMessageConfiscateTransaction) Do(ctx context.Context) error { | ||
_, err := a.Config().Services.Node.AddToConfiscationTransactionWhitelist(ctx, a.Transactions) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -1,19 +1,75 @@ | ||
package models | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"encoding/binary" | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/libsv/go-bn/models" | ||
) | ||
|
||
// AlertMessageFreezeUtxo is the message for freezing UTXOs | ||
type AlertMessageFreezeUtxo struct { | ||
AlertMessage | ||
// TODO finish building out this alert type | ||
Funds []models.Fund | ||
} | ||
|
||
type Fund struct { | ||
TransactionOutId [32]byte | ||
Vout [8]byte | ||
EnforceAtHeightStart [8]byte | ||
EnforceAtHeightEnd [8]byte | ||
PolicyExpiresWithConsensus bool | ||
} | ||
|
||
// Read reads the message | ||
func (a *AlertMessageFreezeUtxo) Read(_ []byte) error { | ||
func (a *AlertMessageFreezeUtxo) Read(raw []byte) error { | ||
if len(raw) < 57 { | ||
return fmt.Errorf("freeze alert is less than 58 bytes") | ||
} | ||
if len(raw)%57 != 0 { | ||
return fmt.Errorf("freeze alert is not a multiple of 58 bytes") | ||
} | ||
fundCount := len(raw) / 57 | ||
funds := []models.Fund{} | ||
for i := 0; i < fundCount; i++ { | ||
fund := Fund{ | ||
TransactionOutId: [32]byte(raw[0:32]), | ||
Vout: [8]byte(raw[32:40]), | ||
EnforceAtHeightStart: [8]byte(raw[40:48]), | ||
EnforceAtHeightEnd: [8]byte(raw[48:56]), | ||
} | ||
enforceByte := binary.LittleEndian.Uint16(raw[56:57]) | ||
|
||
if enforceByte != uint16(0) { | ||
fund.PolicyExpiresWithConsensus = true | ||
} | ||
funds = append(funds, models.Fund{ | ||
TxOut: models.TxOut{ | ||
TxId: hex.EncodeToString(fund.TransactionOutId[:]), | ||
Vout: int(binary.LittleEndian.Uint64(fund.Vout[:])), | ||
}, | ||
EnforceAtHeight: []models.Enforce{ | ||
{ | ||
Start: int(binary.LittleEndian.Uint64(fund.EnforceAtHeightStart[:])), | ||
Stop: int(binary.LittleEndian.Uint64(fund.EnforceAtHeightEnd[:])), | ||
}, | ||
}, | ||
PolicyExpiresWithConsensus: fund.PolicyExpiresWithConsensus, | ||
}) | ||
raw = raw[57:] | ||
} | ||
a.Funds = funds | ||
|
||
return nil | ||
} | ||
|
||
// Do performs the message | ||
func (a *AlertMessageFreezeUtxo) Do(_ context.Context) error { | ||
func (a *AlertMessageFreezeUtxo) Do(ctx context.Context) error { | ||
_, err := a.Config().Services.Node.AddToConsensusBlacklist(ctx, a.Funds) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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