Skip to content

Commit 75d0bed

Browse files
committed
Expose protobuf converters
Signed-off-by: Steffen Rattay <steffen@perun.network>
1 parent 9a55da2 commit 75d0bed

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

wire/protobuf/proposalmsgs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func toBaseChannelProposal(protoProp *BaseChannelProposal) (prop client.BaseChan
150150
if err != nil {
151151
return prop, errors.WithMessage(err, "init bals")
152152
}
153-
prop.FundingAgreement = toBalances(protoProp.FundingAgreement)
153+
prop.FundingAgreement = ToBalances(protoProp.FundingAgreement)
154154
if err != nil {
155155
return prop, errors.WithMessage(err, "funding agreement")
156156
}
@@ -214,11 +214,12 @@ func toAllocation(protoAlloc *Allocation) (alloc *channel.Allocation, err error)
214214
return nil, errors.WithMessagef(err, "%d'th sub alloc", i)
215215
}
216216
}
217-
alloc.Balances = toBalances(protoAlloc.Balances)
217+
alloc.Balances = ToBalances(protoAlloc.Balances)
218218
return alloc, nil
219219
}
220220

221-
func toBalances(protoBalances *Balances) (balances channel.Balances) {
221+
// ToBalances parses protobuf balances.
222+
func ToBalances(protoBalances *Balances) (balances channel.Balances) {
222223
balances = make([][]channel.Bal, len(protoBalances.Balances))
223224
for i := range protoBalances.Balances {
224225
balances[i] = toBalance(protoBalances.Balances[i])

wire/protobuf/syncmsgs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func toChannelSyncMsg(protoEnvMsg *Envelope_ChannelSyncMsg) (msg *client.Channel
2929
msg.CurrentTX.Sigs[i] = make([]byte, len(protoMsg.CurrentTx.Sigs[i]))
3030
copy(msg.CurrentTX.Sigs[i], protoMsg.CurrentTx.Sigs[i])
3131
}
32-
msg.CurrentTX.State, err = toState(protoMsg.CurrentTx.State)
32+
msg.CurrentTX.State, err = ToState(protoMsg.CurrentTx.State)
3333
return msg, err
3434
}
3535

wire/protobuf/updatemsgs.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func toVirtualChannelFundingProposalMsg(protoEnvMsg *Envelope_VirtualChannelFund
3535
protoMsg := protoEnvMsg.VirtualChannelFundingProposalMsg
3636

3737
msg = &client.VirtualChannelFundingProposalMsg{}
38-
msg.Initial, err = toSignedState(protoMsg.Initial)
38+
msg.Initial, err = ToSignedState(protoMsg.Initial)
3939
if err != nil {
4040
return nil, errors.WithMessage(err, "initial state")
4141
}
@@ -54,7 +54,7 @@ func toVirtualChannelSettlementProposalMsg(protoEnvMsg *Envelope_VirtualChannelS
5454
protoMsg := protoEnvMsg.VirtualChannelSettlementProposalMsg
5555

5656
msg = &client.VirtualChannelSettlementProposalMsg{}
57-
msg.Final, err = toSignedState(protoMsg.Final)
57+
msg.Final, err = ToSignedState(protoMsg.Final)
5858
if err != nil {
5959
return nil, errors.WithMessage(err, "final state")
6060
}
@@ -90,12 +90,13 @@ func toChannelUpdate(protoUpdate *ChannelUpdateMsg) (update client.ChannelUpdate
9090
update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx)
9191
update.Sig = make([]byte, len(protoUpdate.Sig))
9292
copy(update.Sig, protoUpdate.Sig)
93-
update.State, err = toState(protoUpdate.ChannelUpdate.State)
93+
update.State, err = ToState(protoUpdate.ChannelUpdate.State)
9494
return update, err
9595
}
9696

97-
func toSignedState(protoSignedState *SignedState) (signedState channel.SignedState, err error) {
98-
signedState.Params, err = toParams(protoSignedState.Params)
97+
// ToSignedState parses protobuf signed states.
98+
func ToSignedState(protoSignedState *SignedState) (signedState channel.SignedState, err error) {
99+
signedState.Params, err = ToParams(protoSignedState.Params)
99100
if err != nil {
100101
return signedState, err
101102
}
@@ -104,11 +105,12 @@ func toSignedState(protoSignedState *SignedState) (signedState channel.SignedSta
104105
signedState.Sigs[i] = make([]byte, len(protoSignedState.Sigs[i]))
105106
copy(signedState.Sigs[i], protoSignedState.Sigs[i])
106107
}
107-
signedState.State, err = toState(protoSignedState.State)
108+
signedState.State, err = ToState(protoSignedState.State)
108109
return signedState, err
109110
}
110111

111-
func toParams(protoParams *Params) (*channel.Params, error) {
112+
// ToParams parses protobuf params.
113+
func ToParams(protoParams *Params) (*channel.Params, error) {
112114
app, err := toApp(protoParams.App)
113115
if err != nil {
114116
return nil, err
@@ -128,7 +130,8 @@ func toParams(protoParams *Params) (*channel.Params, error) {
128130
return params, nil
129131
}
130132

131-
func toState(protoState *State) (state *channel.State, err error) {
133+
// ToState parses protobuf states.
134+
func ToState(protoState *State) (state *channel.State, err error) {
132135
state = &channel.State{}
133136
copy(state.ID[:], protoState.Id)
134137
state.Version = protoState.Version

0 commit comments

Comments
 (0)