Skip to content

Commit

Permalink
added txEvaluate()
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Jan 28, 2024
1 parent 3b437a9 commit f00ab0f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
40 changes: 34 additions & 6 deletions docs/WavesKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
|[txBroadcast](#waveskittxbroadcast)|Broadcasts a transaction|
|[txBurn](#waveskittxburn)|Makes burn transaction as an array|
|[txData](#waveskittxdata)|Makes data transaction as an array|
|[txEvaluate](#waveskittxevaluate)|Evaluates a transaction|
|[txInvokeScript](#waveskittxinvokescript)|Makes invoke script transaction as an array|
|[txIssue](#waveskittxissue)|Makes issue transaction as an array|
|[txLease](#waveskittxlease)|Makes lease transaction as an array|
Expand Down Expand Up @@ -456,7 +457,7 @@ Encrypts data with cryptash parameters
**Description**

```php
public ensure (array $tx, int $confirmations, int $sleep, int $timeout, bool $hard)
public ensure (array $tx, int $confirmations, int|float $sleep, int $timeout, bool $hard)
```

Ensures a transaction confirmed and reached required confirmations
Expand All @@ -469,8 +470,8 @@ Ensures a transaction confirmed and reached required confirmations
: Transaction as an array
* `(int) $confirmations`
: Number of confirmations to reach (default: 0)
* `(int) $sleep`
: Seconds to sleep between requests (default: 1)
* `(int|float) $sleep`
: Seconds to sleep between requests (default: 0.5)
* `(int) $timeout`
: Timeout to reach lost status (default: 30)
* `(bool) $hard`
Expand Down Expand Up @@ -1423,7 +1424,7 @@ Sets matcher settings
**Description**

```php
public setNodeAddress (string|array $nodeAddress, int $cacheLifetime, array|null $backupNodes)
public setNodeAddress (string|array $nodeAddress, int|float $cacheLifetime, array|null $backupNodes)
```

Sets node address with cache lifetime and backup node addresses
Expand All @@ -1434,8 +1435,8 @@ Sets node address with cache lifetime and backup node addresses

* `(string|array) $nodeAddress`
: Main node address to work with
* `(int) $cacheLifetime`
: Cache lifetime in seconds (default: 1)
* `(int|float) $cacheLifetime`
: Cache lifetime in seconds (default: 0.5)
* `(array|null) $backupNodes`
: Backup node addresses to fallback

Expand Down Expand Up @@ -1932,6 +1933,33 @@ Makes data transaction as an array
<hr />


### WavesKit::txEvaluate

**Description**

```php
public txEvaluate (array $tx)
```

Evaluates a transaction



**Parameters**

* `(array) $tx`
: Transaction as an array

**Return Values**

`array|false`

> Evaluated transaction as an array or FALSE on failure

<hr />


### WavesKit::txInvokeScript

**Description**
Expand Down
25 changes: 25 additions & 0 deletions src/WavesKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,31 @@ public function txValidate( $tx )
return $json;
}

/**
* Evaluates a transaction
*
* @param array $tx Transaction as an array
*
* @return array|false Evaluated transaction as an array or FALSE on failure
*/
public function txEvaluate( $tx )
{
if( !isset( $tx['dApp'] ) )
return false;

if( false === ( $json = $this->fetch( '/utils/script/evaluate/' . $tx['dApp'], true, json_encode( $tx ) ) ) )
return false;

if( false === ( $json = $this->json_decode( $json ) ) )
return false;

if( !isset( $json['stateChanges'] ) && !isset( $json['error'] ) )
return false;

$json['valid'] = isset( $json['stateChanges'] ) && !isset( $json['error'] );
return $json;
}

/**
* Broadcasts a transaction
*
Expand Down

0 comments on commit f00ab0f

Please sign in to comment.