Skip to content

Commit

Permalink
refactor: rename transaction to tx
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Oct 18, 2024
1 parent 8507d5a commit 3a3e2fd
Show file tree
Hide file tree
Showing 35 changed files with 126 additions and 126 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ type Signer interface {
}
```

### transaction
### tx

- `github.com/darrenvechain/thorgo/crypto/transaction`
- The `transaction` package is a copy of the [vechain/thor/tx](https://github.com/vechain/thor/tree/master/tx) package and can be used to build transactions where `thorgo` does not provide the necessary functionality.
- `github.com/darrenvechain/thorgo/crypto/tx`
- The `tx` package is a copy of the [vechain/thor/tx](https://github.com/vechain/thor/tree/master/tx) package and can be used to build transactions where `thorgo` does not provide the necessary functionality.

### solo

Expand Down Expand Up @@ -190,7 +190,7 @@ import (
"math/big"
"strings"

"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/darrenvechain/thorgo/solo"
"github.com/darrenvechain/thorgo"
"github.com/darrenvechain/thorgo/txmanager"
Expand Down
6 changes: 3 additions & 3 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"

"github.com/darrenvechain/thorgo/client"
"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
Expand Down Expand Up @@ -53,10 +53,10 @@ func (a *Visitor) Storage(key common.Hash) (*client.AccountStorage, error) {

// Call executes a read-only contract call.
func (a *Visitor) Call(calldata []byte) (*client.InspectResponse, error) {
clause := transaction.NewClause(&a.account).WithData(calldata).WithValue(big.NewInt(0))
clause := tx.NewClause(&a.account).WithData(calldata).WithValue(big.NewInt(0))

request := client.InspectRequest{
Clauses: []*transaction.Clause{clause},
Clauses: []*tx.Clause{clause},
}
var (
inspection []client.InspectResponse
Expand Down
14 changes: 7 additions & 7 deletions accounts/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math/big"

"github.com/darrenvechain/thorgo/client"
"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/darrenvechain/thorgo/transactions"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -47,9 +47,9 @@ func (c *Contract) Call(method string, value interface{}, args ...interface{}) e
if err != nil {
return fmt.Errorf("failed to pack method %s: %w", method, err)
}
clause := transaction.NewClause(&c.Address).WithData(packed).WithValue(big.NewInt(0))
clause := tx.NewClause(&c.Address).WithData(packed).WithValue(big.NewInt(0))
request := client.InspectRequest{
Clauses: []*transaction.Clause{clause},
Clauses: []*tx.Clause{clause},
}
var response []client.InspectResponse
if c.revision == nil {
Expand Down Expand Up @@ -103,16 +103,16 @@ func (c *Contract) DecodeCall(data []byte, value interface{}) error {
}

// AsClause returns a transaction clause for the given method and arguments.
func (c *Contract) AsClause(method string, args ...interface{}) (*transaction.Clause, error) {
func (c *Contract) AsClause(method string, args ...interface{}) (*tx.Clause, error) {
packed, err := c.ABI.Pack(method, args...)
if err != nil {
return nil, fmt.Errorf("failed to pack method %s: %w", method, err)
}
return transaction.NewClause(&c.Address).WithData(packed).WithValue(big.NewInt(0)), nil
return tx.NewClause(&c.Address).WithData(packed).WithValue(big.NewInt(0)), nil
}

type TxManager interface {
SendClauses(clauses []*transaction.Clause) (common.Hash, error)
SendClauses(clauses []*tx.Clause) (common.Hash, error)
}

// Send executes a transaction with a single clause.
Expand All @@ -121,7 +121,7 @@ func (c *Contract) Send(manager TxManager, method string, args ...interface{}) (
if err != nil {
return &transactions.Visitor{}, fmt.Errorf("failed to pack method %s: %w", method, err)
}
txId, err := manager.SendClauses([]*transaction.Clause{clause})
txId, err := manager.SendClauses([]*tx.Clause{clause})
if err != nil {
return &transactions.Visitor{}, fmt.Errorf("failed to send transaction: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions accounts/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"

"github.com/darrenvechain/thorgo/client"
"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/darrenvechain/thorgo/transactions"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (d *Deployer) Deploy(sender TxManager, args ...interface{}) (*Contract, com
if err != nil {
return nil, txID, fmt.Errorf("failed to pack contract arguments: %w", err)
}
txID, err = sender.SendClauses([]*transaction.Clause{clause})
txID, err = sender.SendClauses([]*tx.Clause{clause})
if err != nil {
return nil, txID, fmt.Errorf("failed to send contract deployment transaction: %w", err)
}
Expand All @@ -52,12 +52,12 @@ func (d *Deployer) Deploy(sender TxManager, args ...interface{}) (*Contract, com
}

// AsClause returns the contract deployment clause.
func (d *Deployer) AsClause(args ...interface{}) (*transaction.Clause, error) {
func (d *Deployer) AsClause(args ...interface{}) (*tx.Clause, error) {
contractArgs, err := d.abi.Pack("", args...)
if err != nil {
return nil, fmt.Errorf("failed to pack contract arguments: %w", err)
}
bytecode := append(d.bytecode, contractArgs...)
clause := transaction.NewClause(nil).WithData(bytecode).WithValue(d.value)
clause := tx.NewClause(nil).WithData(bytecode).WithValue(d.value)
return clause, nil
}
18 changes: 9 additions & 9 deletions client/accounts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
Expand All @@ -21,14 +21,14 @@ type AccountStorage struct {
}

type InspectRequest struct {
Gas *uint64 `json:"gas,omitempty"`
GasPrice *uint64 `json:"gasPrice,omitempty"`
Caller *common.Address `json:"caller,omitempty"`
ProvedWork *string `json:"provedWork,omitempty"`
GasPayer *common.Address `json:"gasPayer,omitempty"`
Expiration *uint64 `json:"expiration,omitempty"`
BlockRef *string `json:"blockRef,omitempty"`
Clauses []*transaction.Clause `json:"clauses"`
Gas *uint64 `json:"gas,omitempty"`
GasPrice *uint64 `json:"gasPrice,omitempty"`
Caller *common.Address `json:"caller,omitempty"`
ProvedWork *string `json:"provedWork,omitempty"`
GasPayer *common.Address `json:"gasPayer,omitempty"`
Expiration *uint64 `json:"expiration,omitempty"`
BlockRef *string `json:"blockRef,omitempty"`
Clauses []*tx.Clause `json:"clauses"`
}

type InspectResponse struct {
Expand Down
42 changes: 21 additions & 21 deletions client/blocks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
Expand Down Expand Up @@ -31,29 +31,29 @@ func (b *Block) ChainTag() byte {
return b.ID[len(b.ID)-1]
}

func (b *Block) BlockRef() transaction.BlockRef {
return transaction.NewBlockRefFromID(b.ID)
func (b *Block) BlockRef() tx.BlockRef {
return tx.NewBlockRefFromID(b.ID)
}

type BlockTransaction struct {
ID common.Hash `json:"id"`
ChainTag byte `json:"chainTag"`
BlockRef transaction.BlockRef `json:"blockRef"`
Expiration int64 `json:"expiration"`
Clauses []transaction.Clause `json:"clauses"`
GasPriceCoef int64 `json:"gasPriceCoef"`
Gas int64 `json:"gas"`
Origin common.Address `json:"origin"`
Delegator *common.Address `json:"delegator,omitempty"`
Nonce hexutil.Big `json:"nonce"`
DependsOn *common.Hash `json:"dependsOn,omitempty"`
Size int64 `json:"size"`
GasUsed int64 `json:"gasUsed"`
GasPayer common.Address `json:"gasPayer"`
Paid hexutil.Big `json:"paid"`
Reward hexutil.Big `json:"reward"`
Reverted bool `json:"reverted"`
Outputs []Output `json:"outputs"`
ID common.Hash `json:"id"`
ChainTag byte `json:"chainTag"`
BlockRef tx.BlockRef `json:"blockRef"`
Expiration int64 `json:"expiration"`
Clauses []tx.Clause `json:"clauses"`
GasPriceCoef int64 `json:"gasPriceCoef"`
Gas int64 `json:"gas"`
Origin common.Address `json:"origin"`
Delegator *common.Address `json:"delegator,omitempty"`
Nonce hexutil.Big `json:"nonce"`
DependsOn *common.Hash `json:"dependsOn,omitempty"`
Size int64 `json:"size"`
GasUsed int64 `json:"gasUsed"`
GasPayer common.Address `json:"gasPayer"`
Paid hexutil.Big `json:"paid"`
Reward hexutil.Big `json:"reward"`
Reverted bool `json:"reverted"`
Outputs []Output `json:"outputs"`
}

type ExpandedBlock struct {
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"strings"

"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -135,7 +135,7 @@ func (c *Client) ChainTag() byte {
}

// SendTransaction sends a transaction to the node.
func (c *Client) SendTransaction(tx *transaction.Transaction) (*SendTransactionResponse, error) {
func (c *Client) SendTransaction(tx *tx.Transaction) (*SendTransactionResponse, error) {
body := make(map[string]string)
encoded, err := tx.Encoded()
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions client/transactions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
Expand All @@ -26,19 +26,19 @@ type TransactionReceipt struct {
}

type Transaction struct {
ID common.Hash `json:"id"`
ChainTag int64 `json:"chainTag"`
BlockRef transaction.BlockRef `json:"blockRef"`
Expiration int64 `json:"expiration"`
Clauses []transaction.Clause `json:"clauses"`
GasPriceCoef int64 `json:"gasPriceCoef"`
Gas int64 `json:"gas"`
Origin common.Address `json:"origin"`
Delegator *common.Address `json:"delegator"`
Nonce hexutil.Big `json:"nonce"`
DependsOn *common.Hash `json:"dependsOn"`
Size int64 `json:"size"`
Meta TxMeta `json:"meta"`
ID common.Hash `json:"id"`
ChainTag int64 `json:"chainTag"`
BlockRef tx.BlockRef `json:"blockRef"`
Expiration int64 `json:"expiration"`
Clauses []tx.Clause `json:"clauses"`
GasPriceCoef int64 `json:"gasPriceCoef"`
Gas int64 `json:"gas"`
Origin common.Address `json:"origin"`
Delegator *common.Address `json:"delegator"`
Nonce hexutil.Big `json:"nonce"`
DependsOn *common.Hash `json:"dependsOn"`
Size int64 `json:"size"`
Meta TxMeta `json:"meta"`
}

type Transfer struct {
Expand Down
10 changes: 5 additions & 5 deletions client/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"testing"

"github.com/darrenvechain/thorgo/crypto/transaction"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/darrenvechain/thorgo/solo"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
Expand All @@ -15,16 +15,16 @@ func TestClient_SendTransaction(t *testing.T) {
account2 := solo.Keys()[1]
account2Addr := crypto.PubkeyToAddress(account2.PublicKey)

vetClause := transaction.NewClause(&account2Addr).
vetClause := tx.NewClause(&account2Addr).
WithValue(big.NewInt(1000))

txBody := new(transaction.Builder).
txBody := new(tx.Builder).
Gas(3_000_000).
GasPriceCoef(255).
ChainTag(client.ChainTag()).
Expiration(100000000).
BlockRef(transaction.NewBlockRef(0)).
Nonce(transaction.Nonce()).
BlockRef(tx.NewBlockRef(0)).
Nonce(tx.Nonce()).
Clause(vetClause).
Build()

Expand Down
2 changes: 1 addition & 1 deletion crypto/transaction/block_ref.go → crypto/tx/block_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"encoding/binary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"crypto/rand"
Expand Down
2 changes: 1 addition & 1 deletion crypto/transaction/builder.go → crypto/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"encoding/binary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction_test
package tx_test

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion crypto/transaction/clause.go → crypto/tx/clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"math/big"
Expand Down
2 changes: 1 addition & 1 deletion crypto/transaction/features.go → crypto/tx/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

// Features bitset contains tx features.
type Features uint32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion crypto/transaction/nonce.go → crypto/tx/nonce.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package transaction
package tx

import (
"crypto/rand"
Expand Down
2 changes: 1 addition & 1 deletion crypto/transaction/params.go → crypto/tx/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package transaction
package tx

import (
"github.com/ethereum/go-ethereum/params"
Expand Down
Loading

0 comments on commit 3a3e2fd

Please sign in to comment.