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

refactor: evm ecdsa adjustments #135

Merged
merged 23 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Install schnorr workaround script dependencies
run: npm --prefix ./scripts/ install

- name: Install
run: composer update --no-interaction --no-suggest --ignore-platform-reqs

Expand Down
3 changes: 0 additions & 3 deletions scripts/.babelrc

This file was deleted.

150 changes: 0 additions & 150 deletions scripts/dist/schnorr-signer.js

This file was deleted.

2,722 changes: 0 additions & 2,722 deletions scripts/package-lock.json

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/package.json

This file was deleted.

86 changes: 0 additions & 86 deletions scripts/src/schnorr-signer.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/Enums/Fees.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class Fees

public const USERNAME_RESIGNATION = '2500000000';
alfonsobries marked this conversation as resolved.
Show resolved Hide resolved

public const EVM = '0';
public const EVM = '5';
}
44 changes: 14 additions & 30 deletions src/Transactions/Builder/AbstractTransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

namespace ArkEcosystem\Crypto\Transactions\Builder;

use ArkEcosystem\Crypto\Configuration\Fee;
use ArkEcosystem\Crypto\Configuration\Network;
use ArkEcosystem\Crypto\Enums\TypeGroup;
use ArkEcosystem\Crypto\Enums\Types;
use ArkEcosystem\Crypto\Identities\PrivateKey;
use ArkEcosystem\Crypto\Transactions\Types\AbstractTransaction;

Expand All @@ -20,20 +17,13 @@ public function __construct(?array $data = null)
$this->transaction = $this->getTransactionInstance();

$this->transaction->data = $data ?? [
'type' => Types::EVM_CALL->value,
'typeGroup' => TypeGroup::CORE,
'amount' => '0',
'senderPublicKey' => '',
'fee' => Fee::get(Types::EVM_CALL->value),
'nonce' => '1',
'version' => 1,
'network' => Network::get()->pubKeyHash(),
'asset' => [
'evmCall' => [
'gasLimit' => 1000000, // Default gas limit
'payload' => '', // EVM code in hex format
],
],
'value' => '0',
'senderPublicKey' => '',
'gasPrice' => '5',
'nonce' => '1',
'network' => Network::get()->pubKeyHash(),
'gasLimit' => 1_000_000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we set default gas limits for the supported transaction types? e.g.:

  • transfer: 21000
  • validator registration: 500000
  • validator resignation: 150000
  • vote: 200000
  • unvote: 200000
  • default: 1000000

I didn't see them being overwritten in the code in the builders, but maybe I overlooked something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ItsANameToo Deleted all the code related to fees, it's not actually being used anywhere

'data' => '',
];
}

Expand All @@ -49,33 +39,25 @@ public static function new(?array $data = null): static

public function gasLimit(int $gasLimit): static
{
$this->transaction->data['asset']['evmCall']['gasLimit'] = $gasLimit;
$this->transaction->data['gasLimit'] = $gasLimit;

return $this;
}

public function recipient(string $recipientId): static
public function recipientAddress(string $recipientAddress): static
{
$this->transaction->data['recipientId'] = $recipientId;
$this->transaction->data['recipientAddress'] = $recipientAddress;

return $this;
}

public function fee(string $fee): static
public function gasPrice(int $gasPrice): static
{
$this->transaction->data['fee'] = $fee;
$this->transaction->data['gasPrice'] = $gasPrice;

return $this;
}

/**
* Alias for fee.
*/
public function gasPrice(string $gasPrice): static
{
return $this->fee($gasPrice);
}

public function nonce(string $nonce): static
{
$this->transaction->data['nonce'] = $nonce;
Expand All @@ -93,9 +75,11 @@ public function network(int $network): static
public function sign(string $passphrase): static
{
$keys = PrivateKey::fromPassphrase($passphrase);

$this->transaction->data['senderPublicKey'] = $keys->getPublicKey()->getHex();

$this->transaction = $this->transaction->sign($keys);

$this->transaction->data['id'] = $this->transaction->getId();

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Transactions/Builder/EvmCallBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EvmCallBuilder extends AbstractTransactionBuilder
public function payload(string $payload): self
{
$payload = ltrim($payload, '0x');
$this->transaction->data['asset']['evmCall']['payload'] = $payload;
$this->transaction->data['data'] = $payload;

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Transactions/Builder/TransferBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class TransferBuilder extends AbstractTransactionBuilder
{
public function amount(string $amount): self
public function value(string $value): self
{
$this->transaction->data['amount'] = $amount;
$this->transaction->data['value'] = $value;

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Transactions/Builder/ValidatorRegistrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ValidatorRegistrationBuilder extends AbstractTransactionBuilder
{
public function validatorPublicKey(string $validatorPublicKey): self
{
$this->transaction->data['asset']['validatorPublicKey'] = $validatorPublicKey;
$this->transaction->data['validatorPublicKey'] = $validatorPublicKey;

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Transactions/Builder/VoteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class VoteBuilder extends AbstractTransactionBuilder
{
public function vote(string $vote): self
{
$this->transaction->data['asset']['vote'] = $vote;
$this->transaction->data['vote'] = $vote;

return $this;
}
Expand Down
Loading
Loading