package lockstep import ( "encoding/binary" "ripple/types" ) const pullCmd = 0x00 func uint32ToBytes(val uint32) []byte { buf := make([]byte, 4) binary.BigEndian.PutUint32(buf[:4], val) return buf } func prefixTC(instr types.Instruction, tc uint32) types.Instruction { tcBytes := uint32ToBytes(tc) instr.Arguments = append(tcBytes, instr.Arguments...) return instr } func (l *Lockstep) prefixTCAndSend(id types.UserIdentifier, instr types.Instruction, tc uint32) { dtc := prefixTC(instr, tc) l.sender.SendPriority(id, dtc) } func (l *Lockstep) sendValidated(id types.UserIdentifier, instr types.Instruction) { tc := l.st.Storage.MustGetAccount(id).TurnCounter tc-- l.prefixTCAndSend(id, instr, tc) } func (l *Lockstep) sendProposal(id types.UserIdentifier, instr types.Instruction) { tc := l.st.Storage.MustGetAccount(id).TurnCounter l.prefixTCAndSend(id, instr, tc) } func (l *Lockstep) sendPullRequest(id types.UserIdentifier) { tc := l.st.Storage.MustGetAccount(id).TurnCounter tcBytes := uint32ToBytes(tc) instr := types.Instruction{Command: pullCmd, Arguments: tcBytes} l.sender.SendPriority(id, instr) } func (l *Lockstep) sendLastValidated(id types.UserIdentifier) { acc := l.st.Storage.MustGetAccount(id) l.sendValidated(id, acc.LastValidated) }