I'm trying to create a simple example using MAIN_MODULE/SIDE_MODULE based on https://github.com/emscripten-core/emscripten/wiki/Linking#general-dynamic-linking but cannot make it work.
Here's my code:
main.c:
#include <stdio.h>
int side(int a);
int main()
{
printf("hello world %d\n", side(1));
}
side.c:
int side(int a)
{
return a + 1;
}
compile:
emcc side.c -s SIDE_MODULE=1 -o side.wasm
emcc main.c -s MAIN_MODULE=1 -o main.html
index.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var Module
= {
preRun: []
, postRun: []
, print: function (e) {
1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" "));
console.log(e);
}
, printErr: function (e) {
1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" "));
console.error(e)
}
};
Module.dynamicLibraries = ['side.wasm'];
</script>
<script async src="main.js"></script>
</body>
</html>
If I run it with python -m SimpleHTTPServer, I get the following errors:
(index):19 Assertion failed: undefined
printErr # (index):19
abort # main.js:33157
assert # main.js:1074
removeRunDependency # main.js:1984
(anonymous) # main.js:2274
Promise.then (async)
instantiateArrayBuffer # main.js:2272
(anonymous) # main.js:2301
Promise.then (async)
(anonymous) # main.js:2296
Promise.then (async)
instantiateAsync # main.js:2288
createWasm # main.js:2321
Module.asm # main.js:2344
(anonymous) # main.js:31495
(index):19 failed to asynchronously prepare wasm: abort(Assertion failed: undefined) at Error
at jsStackTrace (http://localhost:8000/main.js:1626:13)
at stackTrace (http://localhost:8000/main.js:1643:12)
at abort (http://localhost:8000/main.js:33163:44)
at assert (http://localhost:8000/main.js:1074:5)
at removeRunDependency (http://localhost:8000/main.js:1984:5)
at http://localhost:8000/main.js:2274:7
Any advice or guidance would be greatly appreciated!
Related
I'm pretty new to React Hooks and I'm trying to figure out how to use react-firebase-hooks with custom claims.
My firebase Realtime Database is structured like so :
groups
--- key1
------- clients
------- info
--- key2
------- clients
------- info
Each user has a custom claim named "group" carrying the group Key.
I have this code so far but it's throwing me a:
Uncaught TypeError: Cannot read property 'hasCancelCallback' of undefined
at ChildEventRegistration.createCancelEvent"
function ClientList() {
const [firebaseUser, loadingFirebaseUser] = useAuthState(auth);
const [userGroup, setUserGroup] = useState();
useEffect(() => {
const fetchClaims = async () => {
const {
claims: { group },
} = await firebaseUser.getIdTokenResult();
setUserGroup(group);
};
if (firebaseUser) fetchClaims();
}, [firebase.database(), firebaseUser]);
const [snapshots, loading, error] = useList(
firebase.database().ref(`groups/${userGroup}/clients`)
);
return (
<div>
<h2>List of Clients</h2>
{userGroup && <p>{userGroup}</p>}
{error && <strong>Error: {error}</strong>}
{loading && <span>List: Loading...</span>}
{!loading && snapshots && (
<ul>
{snapshots.map((v) => (
<li key={v.key}>
{v.key}}
</li>
))}
</ul>
)}
</div>
);
}
I might be missing something very obvious here.
Here's a full stack trace of the error :
overrideMethod # react_devtools_backend.js:2557
printWarnings # vendors~main.chunk.js:36207
handleWarnings # vendors~main.chunk.js:36212
push../node_modules/react-dev-utils/webpackHotDevClient.js.connection.onmessage # vendors~main.chunk.js:36277
vendors~main.chunk.js:28144 Uncaught TypeError: Cannot read property 'hasCancelCallback' of undefined
at ChildEventRegistration.createCancelEvent (vendors~main.chunk.js:28144)
at vendors~main.chunk.js:23797
at Array.forEach (<anonymous>)
at viewRemoveEventRegistration (vendors~main.chunk.js:23796)
at syncPointRemoveEventRegistration (vendors~main.chunk.js:24047)
at syncTreeRemoveEventRegistration (vendors~main.chunk.js:24417)
at onComplete (vendors~main.chunk.js:24743)
at Object.onComplete (vendors~main.chunk.js:25874)
at vendors~main.chunk.js:16786
at PersistentConnection.onDataMessage_ (vendors~main.chunk.js:17069)
at Connection.onDataMessage_ (vendors~main.chunk.js:15624)
at Connection.onPrimaryMessageReceived_ (vendors~main.chunk.js:15617)
at WebSocketConnection.onMessage (vendors~main.chunk.js:15497)
at WebSocketConnection.appendFrame_ (vendors~main.chunk.js:15050)
at WebSocketConnection.handleIncomingFrame (vendors~main.chunk.js:15108)
at WebSocket.mySock.onmessage (vendors~main.chunk.js:14984)
ChildEventRegistration.createCancelEvent # vendors~main.chunk.js:28144
(anonymous) # vendors~main.chunk.js:23797
viewRemoveEventRegistration # vendors~main.chunk.js:23796
syncPointRemoveEventRegistration # vendors~main.chunk.js:24047
syncTreeRemoveEventRegistration # vendors~main.chunk.js:24417
onComplete # vendors~main.chunk.js:24743
(anonymous) # vendors~main.chunk.js:25874
(anonymous) # vendors~main.chunk.js:16786
PersistentConnection.onDataMessage_ # vendors~main.chunk.js:17069
Connection.onDataMessage_ # vendors~main.chunk.js:15624
Connection.onPrimaryMessageReceived_ # vendors~main.chunk.js:15617
(anonymous) # vendors~main.chunk.js:15497
WebSocketConnection.appendFrame_ # vendors~main.chunk.js:15050
WebSocketConnection.handleIncomingFrame # vendors~main.chunk.js:15108
mySock.onmessage # vendors~main.chunk.js:14984
So I have a React component called UpdateJobComponent. From here the user can either update a job or create a job (depending on the button they clicked in the previous component). The update of a job works fine however when I try to create a job i get the following errors:
Errors
Put http://localhost:8080/jobs/-1 500
Uncaught (in promise) Error: Request failed with status code 500
at createError
It tells me it's a PUT request and not a POST. However I thought I have it said up properly to match the the createJob PostMapping Controller. Below is the UpdateJobComponent code as well as the service files and also the Controller as well as the JobDataService.
I'm quite sure that the updateJob method in my JobController is receiving the POST and that's why I'm getting the problem but I can't figure out how to make the createJob in the JobController get it.
If you want to see anymore code just let me know, I tried to trim it as much as possible so not to take too long to look over! I'd really appreciate any help you can offer!
UpdateJobComponent
// imports
class UpdateJobComponent extends Component {
constructor(props) {
super(props)
this.state = {
id: this.props.match.params.id,
employer: this.props.match.employer,
description: ''
}
// bind methods
}
componentDidMount() {
if (this.state.id == -1) {
console.log("Not mounting")
return;
}
console.log(this.state.id)
console.log("mounting")
let userName = AuthenticationService.getLoggedUser()
JobDataService.retrieveJob(userName, this.state.id)
.then(response => this.setState({
description: response.data.description,
employer: response.data.employer,
jobTitle: response.data.jobTitle
}))
}
// Error handling for form
validate(values) {
let errors = {} // add validation for every field!!!!!!
if (!values.description) {
errors.description = 'Enter a description'
} else if (values.description.length < 5) {
errors.description = 'Description must be at least 5 characters long'
}
return errors
}
// When save is clicked
onSubmit(values) {
// let employer = this.state.employer
// let id = this.state.id
// let jobTitle = this.state.jobTitle
let job = {
id: this.state.id,
employer: values.employer,
jobTitle: values.jobTitle,
description: values.description
}
if (this.state.id === -1) {
JobDataService.createJob(job)
.then(() => this.props.history.push('/jobs'))
} else {
JobDataService.updateJob(job.jobTitle, job.employer, this.state.id, job)
.then(() => this.props.history.push('/jobs'))
}
}
render() {
let { description, employer, jobTitle } = this.state
return (
<div>
<h3>Update {this.state.employer}'s {this.state.jobTitle} Job</h3>
<div className="container">
<Formik
initialValues={{description: description, employer: employer, jobTitle: jobTitle}}
onSubmit={this.onSubmit}
validateOnChange={false}
validateOnBlur={false}
validate={this.validate}
enableReinitialize={true}
>
{
(props) => (
<Form>
// Formik form, removed to make post smaller...
<div className="btn-group mr-2" role="group" aria-label="First group">
<button className="btn btn-success" type="submit">Save</button>
</div>
JobDataService
// imports
const API_URL = 'http://localhost:8080'
const GET_ALL_JOBS_URL = `${API_URL}/jobs/`
updateJob(jobTitle, employer, id, job) {
return axios.put(`${GET_ALL_JOBS_URL}${id}`, job);
}
createJob(job) {
return axios.post(`${GET_ALL_JOBS_URL}`, job);
}
JobController
#Autowired
private JobService jobService;
#PostMapping("/jobs/")
public ResponseEntity<Job> createJob(#RequestBody Job job) {
Job createdJob = jobService.createJob(job);
java.net.URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(createdJob.getId())
.toUri();
return ResponseEntity.created(uri).build();
}
#PutMapping("/jobs/{id}")
public ResponseEntity<Job> updateJob(#PathVariable long id, #RequestBody Job job) {
job.setId(id);
return ResponseEntity.ok().body(this.jobService.updateJob(job));
}
// Other get and delete methods
JobService
public Job createJob(Job job) {
if(job.getId() == -1 || job.getId() == 0) {
job.setId(++idCounter);
jobRepository.insert(job);
}
return jobRepository.save(job);
}
public Job updateJob(Job job) {
Optional < Job > jobDb = this.jobRepository.findById(job.getId());
if (jobDb.isPresent()) {
Job jobUpdate = jobDb.get();
jobUpdate.setId(job.getId());
jobUpdate.setEmployer(job.getEmployer());
jobUpdate.setJobTitle(job.getJobTitle());
jobUpdate.setDescription(job.getDescription());
jobRepository.save(jobUpdate);
return jobUpdate;
} else {
throw new ResourceNotFoundException("Record not found with id : " + job.getId());
}
}
// Other methods
Edit
Full error message:
PUT http://localhost:8080/jobs/-1 500
dispatchXhrRequest # 1.chunk.js:561
xhrAdapter # 1.chunk.js:411
dispatchRequest # 1.chunk.js:994
Promise.then (async)
request # 1.chunk.js:807
Axios.<computed> # 1.chunk.js:831
wrap # 1.chunk.js:1308
updateJob # main.chunk.js:1428
onSubmit # main.chunk.js:955
(anonymous) # 1.chunk.js:4699
(anonymous) # 1.chunk.js:5014
(anonymous) # 1.chunk.js:4709
Promise.then (async)
(anonymous) # 1.chunk.js:4705
(anonymous) # 1.chunk.js:5014
(anonymous) # 1.chunk.js:4750
(anonymous) # 1.chunk.js:5014
callCallback # 1.chunk.js:16321
invokeGuardedCallbackDev # 1.chunk.js:16370
invokeGuardedCallback # 1.chunk.js:16423
invokeGuardedCallbackAndCatchFirstError # 1.chunk.js:16438
executeDispatch # 1.chunk.js:16569
executeDispatchesInOrder # 1.chunk.js:16594
executeDispatchesAndRelease # 1.chunk.js:16697
executeDispatchesAndReleaseTopLevel # 1.chunk.js:16706
forEachAccumulated # 1.chunk.js:16678
runEventsInBatch # 1.chunk.js:16723
runExtractedPluginEventsInBatch # 1.chunk.js:16865
handleTopLevel # 1.chunk.js:21818
batchedEventUpdates$1 # 1.chunk.js:40326
batchedEventUpdates # 1.chunk.js:17401
dispatchEventForPluginEventSystem # 1.chunk.js:21914
attemptToDispatchEvent # 1.chunk.js:22031
dispatchEvent # 1.chunk.js:21934
unstable_runWithPriority # 1.chunk.js:51411
runWithPriority$2 # 1.chunk.js:28193
discreteUpdates$1 # 1.chunk.js:40343
discreteUpdates # 1.chunk.js:17426
dispatchDiscreteEvent # 1.chunk.js:21901
I just added an if statement in the updateJob method to check if the id was -1. It's far from pretty and will need to be fixed again but wll do for now. Thanks for your time Code-Apprentice!
I am trying to integrate a react app with go-ethereum using web3js.
an event Onsubmit will do the following:
1. Create an account.
2. Open the account.
3. Approve a smart contract with the created account.
Here is my code
import React, { Component } from 'react';
import './App.css';
import web3 from './web3';
....
class App extends Component {
constructor(props){
super(props);
this.state = {requester : '', receiver:'', balance: '', message:''};
}
async componentDidMount(){
const requester = await auth.methods.requester().call();
const receiver = await auth.methods.receiver().call();
const approvers = await auth.methods.approvers(0).call();
const balance = await web3.eth.getBalance(auth.options.address);
this.setState({requester,receiver,balance});
}
onSubmit = async (event)=>{
event.preventDefault();
console.log('Approving the smart contract ..... Mining in process ! ');
var pass = "xxxxxxx"
var newaccount = web3.eth.personal.newAccount(pass);
var promise1 = Promise.resolve(newaccount);
promise1.then(function(value) {
var accountnumber = value;
console.log(accountnumber);
web3.eth.personal.unlockAccount(accountnumber,pass, 1500);
auth.methods.approve().send({gas: '1000000',from: accountnumber});
console.log('Smart Contract approved ! ');
});
};
The account is getting created but while doing the transaction I am receiving the following error.
Approving the smart contract ..... Mining in process ! App.js:57
0x98f76b2673d545F55c0ff1e961f15EF0a7DfBaD3
App.js:71 Smart Contract
approved ! errors.js:29 Uncaught (in promise) Error: Returned error:
authentication needed: password or unlock
at Object.ErrorResponse (errors.js:29)
at index.js:125
at XMLHttpRequest.request.onreadystatechange (index.js:103)
at XMLHttpRequestEventTarget.dispatchEvent (xml-http-request-event-target.js:50)
at XMLHttpRequest._setReadyState (xml-http-request.js:288)
at XMLHttpRequest._onHttpResponseEnd (xml-http-request.js:459)
at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.
(xml-http-request.js:413)
at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.emit
(events.js:139)
at endReadableNT (_stream_readable.js:1030)
at afterTickTwo (index.js:31)
at Item.push../node_modules/process/browser.js.Item.run (browser.js:167)
at drainQueue (browser.js:131) ErrorResponse # errors.js:29 (anonymous) # index.js:125 request.onreadystatechange # index.js:103
XMLHttpRequestEventTarget.dispatchEvent #
xml-http-request-event-target.js:50 XMLHttpRequest._setReadyState #
xml-http-request.js:288 XMLHttpRequest._onHttpResponseEnd #
xml-http-request.js:459 (anonymous) # xml-http-request.js:413 emit #
events.js:139 endReadableNT # _stream_readable.js:1030 afterTickTwo #
index.js:31 push../node_modules/process/browser.js.Item.run #
browser.js:167 drainQueue # browser.js:131 setTimeout (async)
_fireError # index.js:72 sendTxCallback # index.js:465 (anonymous) # index.js:125 request.onreadystatechange # index.js:103
XMLHttpRequestEventTarget.dispatchEvent #
xml-http-request-event-target.js:50 XMLHttpRequest._setReadyState #
xml-http-request.js:288 XMLHttpRequest._onHttpResponseEnd #
xml-http-request.js:459 (anonymous) # xml-http-request.js:413 emit #
events.js:139 endReadableNT # _stream_readable.js:1030 afterTickTwo #
index.js:31 push../node_modules/process/browser.js.Item.run #
browser.js:167 drainQueue # browser.js:131 setTimeout (async)
runTimeout # browser.js:43
push../node_modules/process/browser.js.process.nextTick #
browser.js:156 nextTick # index.js:30 maybeReadMore #
_stream_readable.js:521 addChunk # _stream_readable.js:300 readableAddChunk # _stream_readable.js:278
push../node_modules/readable-stream/lib/_stream_readable.js.Readable.push
# _stream_readable.js:242 (anonymous) # response.js:47 write #
response.js:44
Edit: Changed the code to catch the errors
web3.eth.personal.unlockAccount(accountnumber,pass, 1500, function(err, result){
if(err){
alert("Error"+ err);
return;}
alert("Account Opening: "+ result);});
.....
auth.methods.approve().send({gas: '1000000',from: accountnumber}, function(err, result){
if(err){
alert("Error"+ err);
return;}
alert("Account address: "+ result);
console.log('Smart Contract approved ! ');});
The web3.eth.personal.unlockAccount is returning "true" but the still the auth.methods.approve is giving me the error.
So, after some major changes to the code, I am able to do the following from an onSubmit event on a react app.
Create an account.
Transfer some gas to it.
Unlock the account.
Sign a contract with the account.
Here is the code
onSubmit = async (event)=>{
event.preventDefault();
console.log('Approving the smart contract ..... Mining in process ! ');
var pass = "passsword1"
var newaccount = web3.eth.personal.newAccount(pass);
var promise1 = Promise.resolve(newaccount);
promise1.then(function(value) {
var accountnumber = value;
console.log(accountnumber);
web3.eth.personal.unlockAccount('0x197022acd263e8be0f6b65b10d1e5cdbaa244c17',"*****", 1500, function(err, result){
if(err){
alert("Error"+ err);
return;
}else {
alert("Parent Opening: "+ result);
web3.eth.sendTransaction({
from: "0x197022acd263e8be0f6b65b10d1e5cdbaa244c17",
to: accountnumber,
value: '100000000000000000',
}, function(err, transactionHash) {
if (err) {
console.log(err);
} else {
web3.eth.personal.unlockAccount(accountnumber,pass, 1500, function(err, result){
if(err){
alert("Error"+ err);
return;
}else{
console.log(web3.eth.getBalance(accountnumber));
alert("Child Opening: "+ result);
auth.methods.approve().send({gas: '20000000',from: accountnumber}, function(err, result){
if(err){
alert("Error"+ err);
return;
}else{
console.log("Account address: "+ result);
console.log('Smart Contract approved ! ');
}
});
}
});
}
});
}
});
};
I'm newbie to AngularJS.
Beginning with the script worked fine when in development, after uploaded to production, I got RangeError in my Controller. I confused about this error, even I searching with Google still not solved :(
Here's my script on routeProvider :
.when('/customer/detail/:id', {
title: 'Customer Detail',
templateUrl: 'templates/customer_detail.html',
resolve: {
app: function($q, $rootScope, $location, roles) {
var defer = $q.defer();
if (roles.pageCustomer !== true) {
$location.path('/main.html');
};
defer.resolve();
return defer.promise;
}
}
})
Then on my Controller :
app.controller('ctrl_customer_list', function($scope){
$scope.title = "Customer List";
$('#datatable_customer').DataTable({
bServerSide: true,
bDestroy: true,
responsive: true,
iDisplayLength: 250,
serverSide: true,
columnDefs: [ {
targets: 0,
orderable: false,
targets : 1,
"render": function ( data, type, row, meta ) {
var itemID = row[8];
return '' + data + '';
}
}],
lengthMenu: [ 10, 25, 50, 75, 100, 250, 500, 1000 ],
aaSorting: [[1, 'asc']],
ajax:{
url :"backend/customer/list", // json datasource
type: "post", // type of method ,GET/POST/DELETE
error: function(){
$("#datatable_processing").css("display","none");
}
},
language: {
searchPlaceholder: 'Search...',
sSearch: '',
lengthMenu: '_MENU_ items/page',
}
});
$('.dataTables_length select').select2({ minimumResultsForSearch: Infinity });
});
I got following error when the code has been production :
RangeError: Maximum call stack size exceeded
at Function.n.extend.n.fn.extend (jquery.js:177)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
at Function.n.extend.n.fn.extend (jquery.js:228)
(anonymous) # angular.js:15536
(anonymous) # angular.js:11815
(anonymous) # angular.js:21559
Pg.completeTask # angular.js:21194
(anonymous) # angular.js:6790
setTimeout (async)
h.defer # angular.js:6788
f # angular.js:21554
(anonymous) # select2.js:194
(anonymous) # angular.js:1365
Ba # angular.js:11235
q # angular.js:10554
g # angular.js:9801
g # angular.js:9804
g # angular.js:9804
g # angular.js:9804
g # angular.js:9804
q # angular.js:10548
g # angular.js:9801
g # angular.js:9804
g # angular.js:9804
q # angular.js:10548
g # angular.js:9801
(anonymous) # angular.js:9666
link # angular-route.js:1260
(anonymous) # angular.js:1365
Ba # angular.js:11235
q # angular.js:10554
g # angular.js:9801
(anonymous) # angular.js:9666
(anonymous) # angular.js:10080
d # angular.js:9844
m # angular.js:10604
C # angular-route.js:1209
$broadcast # angular.js:19683
(anonymous) # angular-route.js:749
(anonymous) # angular.js:17914
$digest # angular.js:19075
$apply # angular.js:19463
k # angular.js:13312
w # angular.js:13569
E.onload # angular.js:13474
load (async)
(anonymous) # angular.js:13457
s # angular.js:13257
(anonymous) # angular.js:12998
(anonymous) # angular.js:17914
$digest # angular.js:19075
$apply # angular.js:19463
(anonymous) # angular.js:15270
dispatch # jquery.js:4435
r.handle # jquery.js:4121
I'm using AngularJS 1.7.5 and GruntTasker.
Any advice? Many thanks for helping
(sorry my english)
just update to resolve issue. First, I follow instruction as #numbtongue mention. It's finally found the problems come from AngularJS-select2. I tried to remove AngularJS-select2 from repositories and finally worked !
Thank you very much #numbtongue as instruction debugging with Chrome.
PS:
With the debugger you can see, how many script execute within a time.
I use angular to upload the file as below :
If I run the following code, I get 403(Forbidden)
var contextRoot = "http://localhost\\:6060/nomunoli";
...
...
uploadFile : function(taglist, description, userid, file) {
return $upload.upload({
url : contextRoot + "/auth/insertNMNL001FUN02",
fields : {
'description' : description,
'userId' : userid,
'tagList' : taglist,
},
file : file,
fileFormDataName : 'file'
});
},
...
In debugger console
POST http://localhost/:6060/nomunoli/auth/insertNMNL001FUN02 403 (Forbidden)
b # angular.min.js:79
s # angular.min.js:74
c.$get.f # angular.min.js:71
l.promise.then.J # angular.min.js:101
(anonymous function) # angular.min.js:102
a.$get.h.$eval # angular.min.js:113
a.$get.h.$digest # angular.min.js:110
a.$get.h.$apply # angular.min.js:113
(anonymous function) # angular.min.js:195
n.event.dispatch # jquery-2.1.3.min.js:3
n.event.add.r.handle # jquery-2.1.3.min.js:3
When I change the code as below, it is OK.
...
uploadFile : function(taglist, description, userid, file) {
return $upload.upload({
url : "http://localhost\\:6060/nomunoli/auth/insertNMNL001FUN02",
fields : {
'description' : description,
'userId' : userid,
'tagList' : taglist,
},
file : file,
fileFormDataName : 'file'
});
},
...