Skip to content

Commit

Permalink
refactor: UInt16, UInt32, UInt64 -> type: integer, format: uint*
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Jul 4, 2019
1 parent 23cf1c0 commit 6d3bd5c
Show file tree
Hide file tree
Showing 73 changed files with 772 additions and 1,745 deletions.
4 changes: 2 additions & 2 deletions aeternity/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func (c *Client) GetHeight() (height uint64, err error) {
return
}
if tb.KeyBlock == nil {
height = uint64(tb.MicroBlock.Height)
height = *tb.MicroBlock.Height
return
}
height = uint64(tb.KeyBlock.Height)
height = *tb.KeyBlock.Height
return
}

Expand Down
4 changes: 2 additions & 2 deletions aeternity/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type ContractConfig struct {
GasPrice big.Int `json:"gas_price" yaml:"gas_price" mapstructure:"gas_price"`
Amount big.Int `json:"amount" yaml:"amount" mapstructure:"amount"`
Deposit big.Int `json:"deposit" yaml:"deposit" mapstructure:"deposit"`
VMVersion uint64 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
ABIVersion uint64 `json:"abi_version" yaml:"abi_version" mapstructure:"abi_version"`
VMVersion uint16 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
ABIVersion uint16 `json:"abi_version" yaml:"abi_version" mapstructure:"abi_version"`
}

// OracleConfig configurations for contracts
Expand Down
8 changes: 4 additions & 4 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetNextNonce(c getAccounter, accountID string) (nextNonce uint64, err error
if err != nil {
return
}
nextNonce = uint64(a.Nonce) + 1
nextNonce = *a.Nonce + 1
return
}

Expand Down Expand Up @@ -220,7 +220,7 @@ func (n *Aens) NameRevokeTx(name string, recipientAddress string) (tx NameRevoke
}

// OracleRegisterTx create a new oracle
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue, abiVersion uint64) (tx OracleRegisterTx, err error) {
func (o *Oracle) OracleRegisterTx(querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue uint64, abiVersion uint16) (tx OracleRegisterTx, err error) {
ttl, nonce, err := GetTTLNonce(o.Client, o.Account.Address, Config.Client.TTL)
if err != nil {
return OracleRegisterTx{}, err
Expand Down Expand Up @@ -264,7 +264,7 @@ func (o *Oracle) OracleRespondTx(OracleID string, QueryID string, Response strin
}

// ContractCreateTx returns a transaction for creating a contract on the chain
func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint64, Deposit, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCreateTx, err error) {
func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, Deposit, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCreateTx, err error) {
ttl, nonce, err := GetTTLNonce(c.Client, c.Account.Address, Config.Client.TTL)
if err != nil {
return ContractCreateTx{}, err
Expand All @@ -275,7 +275,7 @@ func (c *Contract) ContractCreateTx(Code string, CallData string, VMVersion, Abi
}

// ContractCallTx returns a transaction for calling a contract on the chain
func (c *Contract) ContractCallTx(ContractID, CallData string, AbiVersion uint64, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCallTx, err error) {
func (c *Contract) ContractCallTx(ContractID, CallData string, AbiVersion uint16, Amount, Gas, GasPrice, Fee big.Int) (tx ContractCallTx, err error) {
ttl, nonce, err := GetTTLNonce(c.Client, c.Account.Address, Config.Client.TTL)
if err != nil {
return ContractCallTx{}, err
Expand Down
96 changes: 49 additions & 47 deletions aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ func (tx *SpendTx) JSON() (string, error) {
swaggerT := models.SpendTx{
Amount: utils.BigInt(tx.Amount),
Fee: utils.BigInt(tx.Fee),
Nonce: models.Uint64(tx.Nonce),
Nonce: tx.Nonce,
Payload: models.EncodedByteArray(tx.Payload),
RecipientID: models.EncodedPubkey(tx.RecipientID),
SenderID: models.EncodedPubkey(tx.SenderID),
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}
output, err := swaggerT.MarshalBinary()
return string(output), err
Expand Down Expand Up @@ -250,8 +250,8 @@ func (tx *NamePreclaimTx) JSON() (string, error) {
AccountID: models.EncodedPubkey(tx.AccountID),
CommitmentID: models.EncodedValue(tx.CommitmentID),
Fee: utils.BigInt(tx.Fee),
Nonce: models.Uint64(tx.AccountNonce),
TTL: models.Uint64(tx.TTL),
Nonce: tx.AccountNonce,
TTL: tx.TTL,
}
output, err := swaggerT.MarshalBinary()
return string(output), err
Expand Down Expand Up @@ -320,8 +320,8 @@ func (tx *NameClaimTx) JSON() (string, error) {
Fee: utils.BigInt(tx.Fee),
Name: &nameAPIEncoded,
NameSalt: utils.BigInt(tx.NameSalt),
Nonce: models.Uint64(tx.AccountNonce),
TTL: models.Uint64(tx.TTL),
Nonce: tx.AccountNonce,
TTL: tx.TTL,
}

output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -435,13 +435,13 @@ func (tx *NameUpdateTx) JSON() (string, error) {

swaggerT := models.NameUpdateTx{
AccountID: models.EncodedPubkey(tx.AccountID),
ClientTTL: models.Uint64(tx.ClientTTL),
ClientTTL: &tx.ClientTTL,
Fee: utils.BigInt(tx.Fee),
NameID: models.EncodedValue(tx.NameID),
NameTTL: models.Uint64(tx.NameTTL),
Nonce: models.Uint64(tx.AccountNonce),
NameTTL: &tx.NameTTL,
Nonce: tx.AccountNonce,
Pointers: swaggerNamePointers,
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}

output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -511,8 +511,8 @@ func (tx *NameRevokeTx) JSON() (string, error) {
AccountID: models.EncodedPubkey(tx.AccountID),
Fee: utils.BigInt(tx.Fee),
NameID: models.EncodedValue(tx.NameID),
Nonce: models.Uint64(tx.AccountNonce),
TTL: models.Uint64(tx.TTL),
Nonce: tx.AccountNonce,
TTL: tx.TTL,
}

output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -589,9 +589,9 @@ func (tx *NameTransferTx) JSON() (string, error) {
AccountID: models.EncodedPubkey(tx.AccountID),
Fee: utils.BigInt(tx.Fee),
NameID: models.EncodedValue(tx.NameID),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
RecipientID: models.EncodedPubkey(tx.RecipientID),
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}

output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -627,7 +627,7 @@ type OracleRegisterTx struct {
QueryFee big.Int
OracleTTLType uint64
OracleTTLValue uint64
AbiVersion uint64
AbiVersion uint16
Fee big.Int
TTL uint64
}
Expand Down Expand Up @@ -678,25 +678,25 @@ func (tx *OracleRegisterTx) JSON() (string, error) {
ttlTypeStr := ttlTypeIntToStr(tx.OracleTTLType)

swaggerT := models.OracleRegisterTx{
AbiVersion: models.Uint16(tx.AbiVersion),
AbiVersion: tx.AbiVersion,
AccountID: models.EncodedPubkey(tx.AccountID),
Fee: utils.BigInt(tx.Fee),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
OracleTTL: &models.TTL{
Type: &ttlTypeStr,
Value: models.Uint64(tx.OracleTTLValue),
Value: &tx.OracleTTLValue,
},
QueryFee: utils.BigInt(tx.QueryFee),
QueryFormat: &tx.QuerySpec,
ResponseFormat: &tx.ResponseSpec,
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}
output, err := swaggerT.MarshalBinary()
return string(output), err
}

// NewOracleRegisterTx is a constructor for a OracleRegisterTx struct
func NewOracleRegisterTx(accountID string, accountNonce uint64, querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue, abiVersion uint64, txFee big.Int, txTTL uint64) OracleRegisterTx {
func NewOracleRegisterTx(accountID string, accountNonce uint64, querySpec, responseSpec string, queryFee big.Int, oracleTTLType, oracleTTLValue uint64, abiVersion uint16, txFee big.Int, txTTL uint64) OracleRegisterTx {
return OracleRegisterTx{accountID, accountNonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, abiVersion, txFee, txTTL}
}

Expand Down Expand Up @@ -735,13 +735,13 @@ func (tx *OracleExtendTx) JSON() (string, error) {

swaggerT := models.OracleExtendTx{
Fee: utils.BigInt(tx.Fee),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
OracleID: models.EncodedPubkey(tx.OracleID),
OracleTTL: &models.RelativeTTL{
Type: &oracleTTLTypeStr,
Value: models.Uint64(tx.OracleTTLValue),
Value: &tx.OracleTTLValue,
},
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}

output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -804,20 +804,20 @@ func (tx *OracleQueryTx) JSON() (string, error) {

swaggerT := models.OracleQueryTx{
Fee: utils.BigInt(tx.Fee),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
OracleID: models.EncodedPubkey(tx.OracleID),
Query: &tx.Query,
QueryFee: utils.BigInt(tx.QueryFee),
QueryTTL: &models.TTL{
Type: &queryTTLTypeStr,
Value: models.Uint64(tx.QueryTTLValue),
Value: &tx.QueryTTLValue,
},
ResponseTTL: &models.RelativeTTL{
Type: &responseTTLTypeStr,
Value: models.Uint64(tx.ResponseTTLValue),
Value: &tx.ResponseTTLValue,
},
SenderID: models.EncodedPubkey(tx.SenderID),
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}

output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -872,15 +872,15 @@ func (tx *OracleRespondTx) JSON() (string, error) {

swaggerT := models.OracleRespondTx{
Fee: utils.BigInt(tx.Fee),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
OracleID: models.EncodedPubkey(tx.OracleID),
QueryID: models.EncodedValue(tx.QueryID),
Response: &tx.Response,
ResponseTTL: &models.RelativeTTL{
Type: &responseTTLTypeStr,
Value: models.Uint64(tx.ResponseTTLValue),
Value: &tx.ResponseTTLValue,
},
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}
output, err := swaggerT.MarshalBinary()
return string(output), err
Expand All @@ -897,8 +897,8 @@ type ContractCreateTx struct {
OwnerID string
AccountNonce uint64
Code string
VMVersion uint64
AbiVersion uint64
VMVersion uint16
AbiVersion uint16
Deposit big.Int
Amount big.Int
Gas big.Int
Expand All @@ -908,9 +908,9 @@ type ContractCreateTx struct {
CallData string
}

func encodeVMABI(VMVersion, ABIVersion uint64) []byte {
vmBytes := utils.NewIntFromUint64(VMVersion).Bytes()
abiBytes := utils.NewIntFromUint64(ABIVersion).Bytes()
func encodeVMABI(VMVersion, ABIVersion uint16) []byte {
vmBytes := big.NewInt(int64(VMVersion)).Bytes()
abiBytes := big.NewInt(int64(ABIVersion)).Bytes()
vmAbiBytes := []byte{}
vmAbiBytes = append(vmAbiBytes, vmBytes...)
vmAbiBytes = append(vmAbiBytes, leftPadByteSlice(2, abiBytes)...)
Expand Down Expand Up @@ -952,18 +952,19 @@ func (tx *ContractCreateTx) RLP() (rlpRawMsg []byte, err error) {

// JSON representation of a Tx is useful for querying the node's debug endpoint
func (tx *ContractCreateTx) JSON() (string, error) {
g := tx.Gas.Uint64()
swaggerT := models.ContractCreateTx{
OwnerID: models.EncodedPubkey(tx.OwnerID),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
Code: models.EncodedByteArray(tx.Code),
VMVersion: models.Uint16(tx.VMVersion),
AbiVersion: models.Uint16(tx.AbiVersion),
VMVersion: &tx.VMVersion,
AbiVersion: &tx.AbiVersion,
Deposit: utils.BigInt(tx.Deposit),
Amount: utils.BigInt(tx.Amount),
Gas: models.Uint64(tx.Gas.Uint64()),
Gas: &g,
GasPrice: utils.BigInt(tx.GasPrice),
Fee: utils.BigInt(tx.Fee),
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
CallData: models.EncodedByteArray(tx.CallData),
}
output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -991,7 +992,7 @@ func (tx *ContractCreateTx) ContractID() (string, error) {
}

// NewContractCreateTx is a constructor for a ContractCreateTx struct
func NewContractCreateTx(OwnerID string, AccountNonce uint64, Code string, VMVersion, AbiVersion uint64, Deposit, Amount, Gas, GasPrice, Fee big.Int, TTL uint64, CallData string) ContractCreateTx {
func NewContractCreateTx(OwnerID string, AccountNonce uint64, Code string, VMVersion, AbiVersion uint16, Deposit, Amount, Gas, GasPrice, Fee big.Int, TTL uint64, CallData string) ContractCreateTx {
return ContractCreateTx{
OwnerID: OwnerID,
AccountNonce: AccountNonce,
Expand All @@ -1017,25 +1018,26 @@ type ContractCallTx struct {
Amount big.Int
Gas big.Int
GasPrice big.Int
AbiVersion uint64
AbiVersion uint16
CallData string
Fee big.Int
TTL uint64
}

// JSON representation of a Tx is useful for querying the node's debug endpoint
func (tx *ContractCallTx) JSON() (string, error) {
gas := tx.Gas.Uint64()
swaggerT := models.ContractCallTx{
CallerID: models.EncodedPubkey(tx.CallerID),
Nonce: models.Uint64(tx.AccountNonce),
Nonce: tx.AccountNonce,
ContractID: models.EncodedPubkey(tx.ContractID),
Amount: utils.BigInt(tx.Amount),
Gas: models.Uint64(tx.Gas.Uint64()),
Gas: &gas,
GasPrice: utils.BigInt(tx.GasPrice),
AbiVersion: models.Uint16(tx.AbiVersion),
AbiVersion: &tx.AbiVersion,
CallData: models.EncodedByteArray(tx.CallData),
Fee: utils.BigInt(tx.Fee),
TTL: models.Uint64(tx.TTL),
TTL: tx.TTL,
}
output, err := swaggerT.MarshalBinary()
return string(output), err
Expand Down Expand Up @@ -1089,7 +1091,7 @@ func (tx *ContractCallTx) FeeEstimate() (*big.Int, error) {
}

// NewContractCallTx is a constructor for a ContractCallTx struct
func NewContractCallTx(CallerID string, AccountNonce uint64, ContractID string, Amount, Gas, GasPrice big.Int, AbiVersion uint64, CallData string, Fee big.Int, TTL uint64) ContractCallTx {
func NewContractCallTx(CallerID string, AccountNonce uint64, ContractID string, Amount, Gas, GasPrice big.Int, AbiVersion uint16, CallData string, Fee big.Int, TTL uint64) ContractCallTx {
return ContractCallTx{
CallerID: CallerID,
AccountNonce: AccountNonce,
Expand Down

0 comments on commit 6d3bd5c

Please sign in to comment.