Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug where a promise was unhandled. #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,27 @@ function contractFactory(query) {
}

if (methodObject.type === 'function') {
return new Promise((resolve, reject) => {
function newMethodCallback(callbackError, callbackResult) {
if (queryMethod === 'call' && !callbackError) {
try {
const decodedMethodResult = abi.decodeMethod(methodObject, callbackResult);

resolve(decodedMethodResult);
methodCallback(null, decodedMethodResult);
} catch (decodeFormattingError) {
const decodingError = new Error(`[ethjs-contract] while formatting incoming raw call data ${JSON.stringify(callbackResult)} ${decodeFormattingError}`);

reject(decodingError);
methodCallback(decodingError, null);
}
} else if (queryMethod === 'sendTransaction' && !callbackError) {
resolve(callbackResult);
methodCallback(null, callbackResult);
} else {
reject(callbackError);
methodCallback(callbackError, null);
if (hasTransactionObject(methodArgs)) providedTxObject = methodArgs.pop();
var methodTxObject = Object.assign({}, self.defaultTxObject, providedTxObject, {
to: self.address
});
methodTxObject.data = abi.encodeMethod(methodObject, methodArgs);

if (methodObject.constant === false) {
queryMethod = 'sendTransaction';
}

return query[queryMethod](methodTxObject).then(callbackResult => {
if (queryMethod === 'call') {
try {
var decodedMethodResult = abi.decodeMethod(methodObject, callbackResult);
return decodedMethodResult;
} catch (decodeFormattingError) {
throw new Error('[ethjs-contract] while formatting incoming raw call data ' + JSON.stringify(callbackResult) + ' ' + decodeFormattingError);
}
} else if (queryMethod === 'sendTransaction') {
return callbackResult;
}

if (hasTransactionObject(methodArgs)) providedTxObject = methodArgs.pop();
const methodTxObject = Object.assign({},
self.defaultTxObject,
providedTxObject, {
to: self.address,
});
methodTxObject.data = abi.encodeMethod(methodObject, methodArgs);

if (methodObject.constant === false) {
queryMethod = 'sendTransaction';
}

query[queryMethod](methodTxObject, newMethodCallback);
});
} else if (methodObject.type === 'event') {
const filterInputTypes = getKeys(methodObject.inputs, 'type', false);
Expand Down