Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created May 8, 2018 15:09
Show Gist options
  • Save jjn1056/258bf3c2c3ea95cb98f7123168267165 to your computer and use it in GitHub Desktop.
Save jjn1056/258bf3c2c3ea95cb98f7123168267165 to your computer and use it in GitHub Desktop.
## Current
sub new_transaction($self, $c) : POST At('/transactions/new') {
my $form = $c->model('Form::Transaction');
if($form->validated) {
if(my $result = $c->model('Blockchain')->submit_transaction(%{$form->fif})) {
return $c->view('TransactionAdded', transaction_result=>$result)->http_201;
} else {
return $c->view('InvalidTransaction')->http_406;
}
} else {
return $c->view('InvalidTransaction', errors=>$form->errors)->http_406;
}
}
## Flat API approach
sub new_transaction($self, $c) : POST At('/transactions/new') {
my $form = $c->form('Transaction');
if($form->validated) {
if(my $result = $c->blockchain->submit_transaction(%{$form->fif})) {
return $c->send_json(201, +{transaction_result=>$result});
} else {
return $c->send_json(406, +{message=>'Transaction Error!'});
}
} else {
$c->send_json(400, +{errors=>$form->errors'});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment