@@ -30,31 +30,31 @@ type AssetIDKey struct {
3030
3131// Funder is a multi-ledger funder.
3232// funders is a map of LedgerIDs corresponding to a funder on some chain.
33- // egoisticChains is a map of LedgerIDs corresponding to a boolean indicating whether the chain should be funded last.
33+ // egoistic controls whether the funder uses the egoisticIndex to control the funding order.
34+ // egoisticIndex controls which participant index will fund last.
3435type Funder struct {
35- funders map [AssetIDKey ]channel.Funder
36- egoisticChains map [AssetIDKey ]bool
36+ funders map [AssetIDKey ]channel.Funder
37+ egoistic bool
38+ egoisticIndex int
3739}
3840
3941// NewFunder creates a new funder.
4042func NewFunder () * Funder {
4143 return & Funder {
42- funders : make (map [AssetIDKey ]channel.Funder ),
43- egoisticChains : make (map [AssetIDKey ]bool ),
44+ funders : make (map [AssetIDKey ]channel.Funder ),
4445 }
4546}
4647
4748// RegisterFunder registers a funder for a given ledger.
4849func (f * Funder ) RegisterFunder (l AssetID , lf channel.Funder ) {
4950 key := AssetIDKey {BackendID : l .BackendID (), LedgerID : string (l .LedgerID ().MapKey ())}
5051 f .funders [key ] = lf
51- f .egoisticChains [key ] = false
5252}
5353
54- // SetEgoisticChain sets the egoistic chain flag for a given ledger.
55- func (f * Funder ) SetEgoisticChain ( l AssetID , id int , egoistic bool ) {
56- key := AssetIDKey { BackendID : l . BackendID (), LedgerID : string ( l . LedgerID (). MapKey ())}
57- f .egoisticChains [ key ] = egoistic
54+ // SetEgoisticPart sets the egoistic chain flag for a given ledger.
55+ func (f * Funder ) SetEgoisticPart ( index int ) {
56+ f . egoisticIndex = index
57+ f .egoistic = true
5858}
5959
6060// Fund funds a multi-ledger channel. It dispatches funding calls to all
@@ -74,9 +74,8 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error {
7474 var egoisticLedgers []AssetID
7575 var nonEgoisticLedgers []AssetID
7676
77- for _ , l := range assetIDs {
78- key := AssetIDKey {BackendID : l .BackendID (), LedgerID : string (l .LedgerID ().MapKey ())}
79- if f .egoisticChains [key ] {
77+ for i , l := range assetIDs {
78+ if f .egoisticIndex == i {
8079 egoisticLedgers = append (egoisticLedgers , l )
8180 } else {
8281 nonEgoisticLedgers = append (nonEgoisticLedgers , l )
0 commit comments