package transport import( "encoding/binary" "fmt" "net" "ripple/types" ) const ( accountType = 0 counterpartType = 2 ) func getAddr(addrStr string, port int) (*net.UDPAddr, error) { dest := fmt.Sprintf("%s:%d", addrStr, port) return net.ResolveUDPAddr("udp", dest) } func parseTxFrom(tx []byte) types.UserIdentifier { raw := tx[33:97] return types.NewUserIdentifierFromBytes(raw) } func buildTx(txType byte, toUsername string, fromID types.UserIdentifier, counter uint32, instr types.Instruction) []byte { buf := make([]byte, 102+len(instr.Arguments)) buf[0] = txType copy(buf[1:33], []byte(toUsername)) copy(buf[33:65], []byte(fromID.Username)) copy(buf[65:97], []byte(fromID.ServerAddress)) binary.BigEndian.PutUint32(buf[97:101], counter) buf[101] = instr.Command copy(buf[102:], instr.Arguments) return buf }