Skip to content
Snippets Groups Projects
Unverified Commit aa508832 authored by Hans Moog's avatar Hans Moog Committed by GitHub
Browse files

Feat: added support for colored coins (#466)


Co-authored-by: default avatarHans Moog <hm@mkjc.net>
parent c6bce7fa
No related branches found
No related tags found
No related merge requests found
......@@ -1134,9 +1134,26 @@ func (tangle *Tangle) bookTransaction(cachedTransaction *transaction.CachedTrans
// book transaction into target branch
transactionMetadata.SetBranchID(targetBranch.ID())
// create color for newly minted coins
mintedColor, _, err := balance.ColorFromBytes(transactionToBook.ID().Bytes())
if err != nil {
panic(err) // this should never happen (a transaction id is always a valid color)
}
// book outputs into the target branch
transactionToBook.Outputs().ForEach(func(address address.Address, balances []*balance.Balance) bool {
newOutput := NewOutput(address, transactionToBook.ID(), targetBranch.ID(), balances)
// create correctly colored balances (replacing color of newly minted coins with color of transaction id)
coloredBalances := make([]*balance.Balance, len(balances))
for i, currentBalance := range balances {
if currentBalance.Color() == balance.ColorNew {
coloredBalances[i] = balance.New(mintedColor, currentBalance.Value())
} else {
coloredBalances[i] = currentBalance
}
}
// store output
newOutput := NewOutput(address, transactionToBook.ID(), targetBranch.ID(), coloredBalances)
newOutput.setSolid(true)
tangle.outputStorage.Store(newOutput).Release()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment