"encoding/json"
"io/ioutil"
"os"
+
+ "github.com/bytom/vapor/consensus"
+ "github.com/bytom/vapor/protocol/bc"
+ "github.com/bytom/vapor/protocol/bc/types"
)
func ExportFederationFile(fedFile string, config *Config) error {
return json.NewDecoder(file).Decode(config.Federation)
}
+
+type FederationAssetFilter struct {
+ whitelist map[string]struct{}
+}
+
+func NewFederationAssetFilter(whitelist []*bc.AssetID) *FederationAssetFilter {
+ f := &FederationAssetFilter{whitelist: make(map[string]struct{})}
+ f.whitelist[consensus.BTMAssetID.String()] = struct{}{}
+ for _, asset := range whitelist {
+ f.whitelist[asset.String()] = struct{}{}
+ }
+ return f
+}
+
+func (f *FederationAssetFilter) IsDust(tx *types.Tx) bool {
+ for _, input := range tx.Inputs {
+ assetID := input.AssetID()
+ if _, ok := f.whitelist[assetID.String()]; !ok {
+ return true
+ }
+ }
+
+ for _, output := range tx.Outputs {
+ assetID := output.AssetAmount().AssetId
+ if _, ok := f.whitelist[assetID.String()]; !ok {
+ return true
+ }
+ }
+
+ return false
+}
dispatcher := event.NewDispatcher()
movCore := mov.NewMovCore(config.DBBackend, config.DBDir(), consensus.ActiveNetParams.MovStartHeight)
- txPool := protocol.NewTxPool(store, []protocol.DustFilterer{movCore}, dispatcher)
+ assetFilter := cfg.NewFederationAssetFilter(config.Federation.AssetWhitelist)
+ txPool := protocol.NewTxPool(store, []protocol.DustFilterer{movCore, assetFilter}, dispatcher)
chain, err := protocol.NewChain(store, txPool, []protocol.Protocoler{movCore}, dispatcher)
if err != nil {
cmn.Exit(cmn.Fmt("Failed to create chain structure: %v", err))