return tx, nil
}
-func (e *Engine) addMatchTxFeeOutput(txData *types.TxData, orders []*common.Order, fees []*bc.AssetAmount) error {
+func (e *Engine) addMatchTxFeeOutput(txData *types.TxData, fees []*bc.AssetAmount) error {
for _, feeAmount := range fees {
txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(*feeAmount.AssetId, feeAmount.Amount, e.rewardProgram))
}
refoundAmount := map[bc.AssetID]uint64{}
- refoundAddress := [][]byte{}
+ refoundScript := [][]byte{}
for _, input := range txData.Inputs {
refoundAmount[input.AssetID()] += input.Amount()
contractArgs, err := segwit.DecodeP2WMCProgram(input.ControlProgram())
return err
}
- refoundAddress = append(refoundAddress, contractArgs.SellerProgram)
+ refoundScript = append(refoundScript, contractArgs.SellerProgram)
}
for _, output := range txData.Outputs {
}
}
- refoundCount := len(refoundAddress)
- for asset, amount := range refoundAmount {
+ refoundCount := len(refoundScript)
+ for assetID, amount := range refoundAmount {
averageAmount := amount / uint64(refoundCount)
if averageAmount == 0 {
averageAmount = 1
}
for i := 0; i < refoundCount && amount > 0; i++ {
- txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(asset,
- averageAmount, refoundAddress[i]))
+ txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(assetID, averageAmount, refoundScript[i]))
amount -= averageAmount
}
}
return nil, err
}
- if err := e.addMatchTxFeeOutput(txData, orders, allocatedAssets.Fees); err != nil {
+ if err := e.addMatchTxFeeOutput(txData, allocatedAssets.Fees); err != nil {
return nil, err
}
Fees []*bc.AssetAmount
}
-// RefundAssets represent alias for assetAmount array, because each transaction participant can be refunded multiple assets
-type RefundAssets [][]*bc.AssetAmount
-
-// Add used to add a refund to specify order
-func (r RefundAssets) Add(index int, asset bc.AssetID, amount uint64) {
- if index >= len(r) {
- index = 0
- }
-
- for _, assetAmount := range r[index] {
- if *assetAmount.AssetId == asset {
- assetAmount.Amount += amount
- return
- }
- }
- r[index] = append(r[index], &bc.AssetAmount{AssetId: &asset, Amount: amount})
-}
-
// FeeStrategy used to indicate how to charge a matching fee
type FeeStrategy interface {
// Allocate will allocate the price differential in matching transaction to the participants and the fee