Skip to content

Instantly share code, notes, and snippets.

@mgraczyk
Created June 27, 2018 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgraczyk/19749eb32413253fe94e3f38fdad9805 to your computer and use it in GitHub Desktop.
Save mgraczyk/19749eb32413253fe94e3f38fdad9805 to your computer and use it in GitHub Desktop.
Perlin Avalanche Code Review
func (state *NodeActor) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
// [OT] ... Other cases for starting, stopping
case *messages.QueryRequest:
response := &messages.QueryResponse{}
if msg.Transaction != nil && msg.Transaction.Verify() {
stronglyPreferred := state.node.OnQueryTx(msg.Transaction)
response.Transaction = msg.Transaction.Id
response.StronglyPreferred = stronglyPreferred
ctx.Respond(response)
}
// [OT] Not sure why it always responds with empty. Maybe should return above?
ctx.Respond(response)
case *messages.ApiReceiveTransaction:
// [OT] small race, should be `utxo := atomic.AddUint64(&messages.LastUTXO, 1)-1`
utxo := atomic.LoadUint64(&messages.LastUTXO)
atomic.AddUint64(&messages.LastUTXO, 1)
body := messages.CreateTx(utxo, store.GetKeys().PublicKeyHex(), state.node.SelectParents(), msg.Data)
state.node.OnReceiveTx(body.Sign(store.GetKeys()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment