contract batch send transaction

This commit is contained in:
代码之美 2020-08-16 20:45:41 +08:00 committed by GitHub
parent d69ce96a64
commit a47544b991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -490,7 +490,6 @@ class Contract
if (isset($this->functions)) { if (isset($this->functions)) {
$arguments = func_get_args(); $arguments = func_get_args();
$method = array_splice($arguments, 0, 1)[0]; $method = array_splice($arguments, 0, 1)[0];
$callback = array_pop($arguments);
if (!is_string($method)) { if (!is_string($method)) {
throw new InvalidArgumentException('Please make sure the method is string.'); throw new InvalidArgumentException('Please make sure the method is string.');
@ -505,8 +504,17 @@ class Contract
if (count($functions) < 1) { if (count($functions) < 1) {
throw new InvalidArgumentException('Please make sure the method exists.'); throw new InvalidArgumentException('Please make sure the method exists.');
} }
if (is_callable($callback) !== true) { /* if (is_callable($callback) !== true) {
throw new \InvalidArgumentException('The last param must be callback function.'); throw new \InvalidArgumentException('The last param must be callback function.');
}*/
if ($this->eth->provider->isBatch) {
$callback = null;
} else {
$callback = array_pop($arguments);
if (is_callable($callback) !== true) {
throw new \InvalidArgumentException('The last param must be callback function.');
}
} }
// check the last one in arguments is transaction object // check the last one in arguments is transaction object
@ -564,12 +572,16 @@ class Contract
$transaction['to'] = $this->toAddress; $transaction['to'] = $this->toAddress;
$transaction['data'] = $functionSignature . Utils::stripZero($data); $transaction['data'] = $functionSignature . Utils::stripZero($data);
$this->eth->sendTransaction($transaction, function ($err, $transaction) use ($callback){ if ($this->eth->provider->isBatch) {
if ($err !== null) { $this->eth->sendTransaction($transaction);
return call_user_func($callback, $err, null); } else {
} $this->eth->sendTransaction($transaction, function ($err, $transaction) use ($callback){
return call_user_func($callback, null, $transaction); if ($err !== null) {
}); return call_user_func($callback, $err, null);
}
return call_user_func($callback, null, $transaction);
});
}
} }
} }