Skip to content

Commit

Permalink
Add issue asset to the endpoints
Browse files Browse the repository at this point in the history
Fix also an issue for calculating the required fee.
  • Loading branch information
leganz committed Jul 5, 2020
1 parent 70466f6 commit 74a2862
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
47 changes: 47 additions & 0 deletions docs/assets/issueAsset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Issue an asset

One of the most important parts of a blockchain solution is providing a rocksolid interface for token. In terms of the ardor blockchain they are called "assets".

Currently there are to major types of assets. Singleton and "normal" assets. Normal assets are just the same like singleton assets with one major difference. Singleton assets only exsits once.

From an endpoint perspective the are the same:

```php
public function issueAsset(String $name, $description = null, int $amount = 1, int $decimals = 0, int $chain = 0, array $more = [])
```

```php

use \AMBERSIVE\Ardor\Classes\ArdorAccounts;
use \AMBERSIVE\Ardor\Models\ArdorAssets;

...

public function returnAcccountData():ArdorAccount {

$ardor = new ArdorAssets();
$account = $ardor->issueAsset("My Asset", "Test description", 1, 0, 2);

}
```

Sometime it is required to transport more information within an asset. Therefor you can make use of the second param.
If you pass an array it will automatically transform it to json :

```php

...

public function returnAcccountData():ArdorAccount {

$ardor = new ArdorAssets();
$account = $ardor->issueAsset(
"My Asset", [
"msg" => "Test description"
], 1, 0, 2);

}
```

---
Return to the [overview](../overview.md) page for all topics.
12 changes: 8 additions & 4 deletions src/Classes/ArdorBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,23 @@ public function send(String $method, array $body = [], bool $asAdmin = false, $t

$shouldBroadcast = data_get($body, 'broadcasted', true);

$body["broadcasted"] = false;
$body["broadcast"] = false;
$body["broadcasted"] = false;
$body["broadcast"] = false;
$body["calculateFee"] = true;
$body["feeRateNQTPerFXT"] = -1;

$res = new ArdorTransaction($this->send($method, $body, $asAdmin, $type));

$this->setFee($res->transactionJSON->feeNQT != 0 ? $res->transactionJSON->feeNQT : 1000000);
$this->setFee($res->transactionJSON->feeNQT != 0 ? $res->transactionJSON->feeNQT : ($res->minimumFeeFQT * 1));

$body["broadcast"] = $shouldBroadcast;
$body["broadcasted"] = $shouldBroadcast;
$body["feeNQT"] = $this->getFee();

unset($body["feeRateNQTPerFXT"]);

}
else {
else if (data_get($body,'broadcat', false) !== false) {
$body["broadcast"] = true;
$body["broadcasted"] = true;
$body["feeNQT"] = $this->getFee();
Expand Down
5 changes: 1 addition & 4 deletions src/Tests/Units/Classes/ArdorAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public function testArdorAssetsIssuing():void {
$response = new ArdorMockResponse(200, ['accountCurrencies' => []]);

$ardor = new ArdorAssets();
$asset = $ardor
// ->setClient($this->createApiMock([$response]))
->calculateFee()
->issueAsset("${time}", ["test" => true], 1, 0, 2);
$asset = $ardor->calculateFee()->issueAsset("${time}", ["test" => true, "time" => $time], 1, 0, 2);

$this->assertNotNull($asset);
$this->assertTrue($asset instanceof \AMBERSIVE\Ardor\Models\ArdorTransaction);
Expand Down

0 comments on commit 74a2862

Please sign in to comment.