use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class ConsensusHandler method handleConsensusFailure.
public static void handleConsensusFailure(HandlerContext context, ConsensusFailure failure) throws InvalidMessageIdException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
Lao lao = laoRepository.getLaoByChannel(channel);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(failure.getMessageId());
if (!electInstanceOpt.isPresent()) {
Log.w(TAG, "Failure for invalid messageId : " + failure.getMessageId());
throw new InvalidMessageIdException(failure, failure.getMessageId());
}
ElectInstance electInstance = electInstanceOpt.get();
electInstance.setState(ElectInstance.State.FAILED);
lao.updateElectInstance(electInstance);
laoRepository.updateNodes(lao.getChannel());
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class LAOListAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
HomeLaoLayoutBinding binding;
if (view == null) {
// inflate
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
binding = HomeLaoLayoutBinding.inflate(inflater, viewGroup, false);
} else {
binding = DataBindingUtil.getBinding(view);
}
if (binding == null)
throw new IllegalStateException("Binding could not be find in the view");
LAOItemUserActionsListener userActionsListener = lao -> {
if (openLaoDetail) {
homeViewModel.openLAO(lao.getId());
} else {
homeViewModel.openLaoWallet(lao.getId());
}
};
binding.setLao(laos.get(position));
binding.setLifecycleOwner(lifecycleOwner);
binding.setListener(userActionsListener);
binding.executePendingBindings();
return binding.getRoot();
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class ElectionHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
laoRepository = new LAORepository();
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO
lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
lao.setLastModified(lao.getCreation());
// Create one Roll Call and add it to the LAO
rollCall = new RollCall(lao.getId(), Instant.now().getEpochSecond(), "roll call 1");
lao.setRollCalls(new HashMap<String, RollCall>() {
{
put(rollCall.getId(), rollCall);
}
});
// Create one Election and add it to the LAO
election = new Election(lao.getId(), Instant.now().getEpochSecond(), "election 1");
election.setStart(Instant.now().getEpochSecond());
election.setEnd(Instant.now().getEpochSecond() + 20L);
election.setChannel(lao.getChannel().subChannel(election.getId()));
electionQuestion = new ElectionQuestion("question", "Plurality", false, Arrays.asList("a", "b"), election.getId());
election.setElectionQuestions(Collections.singletonList(electionQuestion));
lao.setElections(new HashMap<String, Election>() {
{
put(election.getId(), election);
}
});
// Add the LAO to the LAORepository
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
// Add the CreateLao message to the LAORepository
MessageGeneral createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class KeyManagerTest method popTokenRetrievingFailsWhenLaoHasNoRollCall.
@Test
public void popTokenRetrievingFailsWhenLaoHasNoRollCall() {
// create LAO
Lao lao = new Lao("lao", Base64DataUtils.generatePublicKey(), 54213424);
KeyManager manager = new KeyManager(androidKeysetManager, wallet);
assertThrows(NoRollCallException.class, () -> manager.getValidPoPToken(lao));
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class LaoDetailViewModel method updateLaoName.
/**
* Method to update the name of a Lao by sending an updateLao msg and a stateLao msg to the
* backend
*/
public void updateLaoName() {
Log.d(TAG, "Updating lao name to " + mLaoName.getValue());
Lao lao = getCurrentLaoValue();
Channel channel = lao.getChannel();
KeyPair mainKey = keyManager.getMainKeyPair();
long now = Instant.now().getEpochSecond();
UpdateLao updateLao = new UpdateLao(mainKey.getPublicKey(), lao.getCreation(), mLaoName.getValue(), now, lao.getWitnesses());
MessageGeneral msg = new MessageGeneral(mainKey, updateLao, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> {
Log.d(TAG, "updated lao name");
dispatchLaoUpdate("lao name", updateLao, lao, channel, msg);
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_update_lao));
disposables.add(disposable);
}
Aggregations