Skip to content

Commit

Permalink
refactor: EncodedHash, EncodedPubkey, EncodedValue, EncodedByteArray …
Browse files Browse the repository at this point in the history
…-> string
  • Loading branch information
randomshinichi committed Jul 4, 2019
1 parent 6d3bd5c commit 0d365f8
Show file tree
Hide file tree
Showing 85 changed files with 373 additions and 877 deletions.
6 changes: 3 additions & 3 deletions aeternity/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func (c *Client) GetStatus() (status *models.Status, err error) {
// PostTransaction post transaction
func (c *Client) PostTransaction(signedEncodedTx, signedEncodedTxHash string) (err error) {
p := external.NewPostTransactionParams().WithBody(&models.Tx{
Tx: models.EncodedByteArray(signedEncodedTx),
Tx: &signedEncodedTx,
})
r, err := c.External.PostTransaction(p)
if err != nil {
return
}
if r.Payload.TxHash != models.EncodedHash(signedEncodedTxHash) {
err = fmt.Errorf("Transaction hash mismatch, expected %s got %s", signedEncodedTxHash, r.Payload.TxHash)
if *r.Payload.TxHash != signedEncodedTxHash {
err = fmt.Errorf("Transaction hash mismatch, expected %s got %s", signedEncodedTxHash, *r.Payload.TxHash)
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WaitForTransactionUntilHeight(c getTransactionByHashHeighter, txHash string

if tx.BlockHeight.LargerThanZero() {
bh := big.Int(tx.BlockHeight)
return bh.Uint64(), string(tx.BlockHash), nil
return bh.Uint64(), *tx.BlockHash, nil
}
time.Sleep(time.Millisecond * time.Duration(Config.Tuning.ChainPollInteval))
}
Expand Down
5 changes: 3 additions & 2 deletions aeternity/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ func (m *mockClient) GetTransactionByHash(hash string) (tx *models.GenericSigned
unminedHeight, _ := utils.NewIntFromString("-1")
minedHeight, _ := utils.NewIntFromString("9")

bh := "bh_someblockhash"
tx = &models.GenericSignedTx{
BlockHash: "bh_someblockhash",
BlockHash: &bh,
BlockHeight: utils.BigInt{},
Hash: "th_transactionhash",
Hash: &hash,
Signatures: nil,
}

Expand Down
58 changes: 29 additions & 29 deletions aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ func (tx *SpendTx) JSON() (string, error) {
Amount: utils.BigInt(tx.Amount),
Fee: utils.BigInt(tx.Fee),
Nonce: tx.Nonce,
Payload: models.EncodedByteArray(tx.Payload),
RecipientID: models.EncodedPubkey(tx.RecipientID),
SenderID: models.EncodedPubkey(tx.SenderID),
Payload: &tx.Payload,
RecipientID: &tx.RecipientID,
SenderID: &tx.SenderID,
TTL: tx.TTL,
}
output, err := swaggerT.MarshalBinary()
Expand Down Expand Up @@ -247,8 +247,8 @@ func (tx *NamePreclaimTx) RLP() (rlpRawMsg []byte, err error) {
// JSON representation of a Tx is useful for querying the node's debug endpoint
func (tx *NamePreclaimTx) JSON() (string, error) {
swaggerT := models.NamePreclaimTx{
AccountID: models.EncodedPubkey(tx.AccountID),
CommitmentID: models.EncodedValue(tx.CommitmentID),
AccountID: &tx.AccountID,
CommitmentID: &tx.CommitmentID,
Fee: utils.BigInt(tx.Fee),
Nonce: tx.AccountNonce,
TTL: tx.TTL,
Expand Down Expand Up @@ -316,7 +316,7 @@ func (tx *NameClaimTx) JSON() (string, error) {
// (base58), not namehash-ed.
nameAPIEncoded := Encode(PrefixName, []byte(tx.Name))
swaggerT := models.NameClaimTx{
AccountID: models.EncodedPubkey(tx.AccountID),
AccountID: &tx.AccountID,
Fee: utils.BigInt(tx.Fee),
Name: &nameAPIEncoded,
NameSalt: utils.BigInt(tx.NameSalt),
Expand Down Expand Up @@ -354,13 +354,13 @@ type NamePointer struct {
}

// EncodeRLP implements rlp.Encoder interface.
func (tx *NamePointer) EncodeRLP(w io.Writer) (err error) {
accountID, err := buildIDTag(IDTagAccount, string(tx.NamePointer.ID))
func (np *NamePointer) EncodeRLP(w io.Writer) (err error) {
accountID, err := buildIDTag(IDTagAccount, *np.NamePointer.ID)
if err != nil {
return
}

err = rlp.Encode(w, []interface{}{tx.Key, accountID})
err = rlp.Encode(w, []interface{}{np.Key, accountID})
if err != nil {
return
}
Expand All @@ -370,7 +370,7 @@ func (tx *NamePointer) EncodeRLP(w io.Writer) (err error) {
// NewNamePointer is a constructor for a swagger generated NamePointer struct.
// It returns a pointer because
func NewNamePointer(key string, id string) *NamePointer {
np := models.NamePointer{ID: models.EncodedPubkey(id), Key: &key}
np := models.NamePointer{ID: &id, Key: &key}
return &NamePointer{
NamePointer: &np,
}
Expand Down Expand Up @@ -434,10 +434,10 @@ func (tx *NameUpdateTx) JSON() (string, error) {
}

swaggerT := models.NameUpdateTx{
AccountID: models.EncodedPubkey(tx.AccountID),
AccountID: &tx.AccountID,
ClientTTL: &tx.ClientTTL,
Fee: utils.BigInt(tx.Fee),
NameID: models.EncodedValue(tx.NameID),
NameID: &tx.NameID,
NameTTL: &tx.NameTTL,
Nonce: tx.AccountNonce,
Pointers: swaggerNamePointers,
Expand Down Expand Up @@ -508,9 +508,9 @@ func (tx *NameRevokeTx) RLP() (rlpRawMsg []byte, err error) {
// JSON representation of a Tx is useful for querying the node's debug endpoint
func (tx *NameRevokeTx) JSON() (string, error) {
swaggerT := models.NameRevokeTx{
AccountID: models.EncodedPubkey(tx.AccountID),
AccountID: &tx.AccountID,
Fee: utils.BigInt(tx.Fee),
NameID: models.EncodedValue(tx.NameID),
NameID: &tx.NameID,
Nonce: tx.AccountNonce,
TTL: tx.TTL,
}
Expand Down Expand Up @@ -586,11 +586,11 @@ func (tx *NameTransferTx) RLP() (rlpRawMsg []byte, err error) {
// JSON representation of a Tx is useful for querying the node's debug endpoint
func (tx *NameTransferTx) JSON() (string, error) {
swaggerT := models.NameTransferTx{
AccountID: models.EncodedPubkey(tx.AccountID),
AccountID: &tx.AccountID,
Fee: utils.BigInt(tx.Fee),
NameID: models.EncodedValue(tx.NameID),
NameID: &tx.NameID,
Nonce: tx.AccountNonce,
RecipientID: models.EncodedPubkey(tx.RecipientID),
RecipientID: &tx.RecipientID,
TTL: tx.TTL,
}

Expand Down Expand Up @@ -679,7 +679,7 @@ func (tx *OracleRegisterTx) JSON() (string, error) {

swaggerT := models.OracleRegisterTx{
AbiVersion: tx.AbiVersion,
AccountID: models.EncodedPubkey(tx.AccountID),
AccountID: &tx.AccountID,
Fee: utils.BigInt(tx.Fee),
Nonce: tx.AccountNonce,
OracleTTL: &models.TTL{
Expand Down Expand Up @@ -736,7 +736,7 @@ func (tx *OracleExtendTx) JSON() (string, error) {
swaggerT := models.OracleExtendTx{
Fee: utils.BigInt(tx.Fee),
Nonce: tx.AccountNonce,
OracleID: models.EncodedPubkey(tx.OracleID),
OracleID: &tx.OracleID,
OracleTTL: &models.RelativeTTL{
Type: &oracleTTLTypeStr,
Value: &tx.OracleTTLValue,
Expand Down Expand Up @@ -805,7 +805,7 @@ func (tx *OracleQueryTx) JSON() (string, error) {
swaggerT := models.OracleQueryTx{
Fee: utils.BigInt(tx.Fee),
Nonce: tx.AccountNonce,
OracleID: models.EncodedPubkey(tx.OracleID),
OracleID: &tx.OracleID,
Query: &tx.Query,
QueryFee: utils.BigInt(tx.QueryFee),
QueryTTL: &models.TTL{
Expand All @@ -816,7 +816,7 @@ func (tx *OracleQueryTx) JSON() (string, error) {
Type: &responseTTLTypeStr,
Value: &tx.ResponseTTLValue,
},
SenderID: models.EncodedPubkey(tx.SenderID),
SenderID: &tx.SenderID,
TTL: tx.TTL,
}

Expand Down Expand Up @@ -873,8 +873,8 @@ func (tx *OracleRespondTx) JSON() (string, error) {
swaggerT := models.OracleRespondTx{
Fee: utils.BigInt(tx.Fee),
Nonce: tx.AccountNonce,
OracleID: models.EncodedPubkey(tx.OracleID),
QueryID: models.EncodedValue(tx.QueryID),
OracleID: &tx.OracleID,
QueryID: &tx.QueryID,
Response: &tx.Response,
ResponseTTL: &models.RelativeTTL{
Type: &responseTTLTypeStr,
Expand Down Expand Up @@ -954,9 +954,9 @@ func (tx *ContractCreateTx) RLP() (rlpRawMsg []byte, err error) {
func (tx *ContractCreateTx) JSON() (string, error) {
g := tx.Gas.Uint64()
swaggerT := models.ContractCreateTx{
OwnerID: models.EncodedPubkey(tx.OwnerID),
OwnerID: &tx.OwnerID,
Nonce: tx.AccountNonce,
Code: models.EncodedByteArray(tx.Code),
Code: &tx.Code,
VMVersion: &tx.VMVersion,
AbiVersion: &tx.AbiVersion,
Deposit: utils.BigInt(tx.Deposit),
Expand All @@ -965,7 +965,7 @@ func (tx *ContractCreateTx) JSON() (string, error) {
GasPrice: utils.BigInt(tx.GasPrice),
Fee: utils.BigInt(tx.Fee),
TTL: tx.TTL,
CallData: models.EncodedByteArray(tx.CallData),
CallData: &tx.CallData,
}
output, err := swaggerT.MarshalBinary()
return string(output), err
Expand Down Expand Up @@ -1028,14 +1028,14 @@ type ContractCallTx struct {
func (tx *ContractCallTx) JSON() (string, error) {
gas := tx.Gas.Uint64()
swaggerT := models.ContractCallTx{
CallerID: models.EncodedPubkey(tx.CallerID),
CallerID: &tx.CallerID,
Nonce: tx.AccountNonce,
ContractID: models.EncodedPubkey(tx.ContractID),
ContractID: &tx.ContractID,
Amount: utils.BigInt(tx.Amount),
Gas: &gas,
GasPrice: utils.BigInt(tx.GasPrice),
AbiVersion: &tx.AbiVersion,
CallData: models.EncodedByteArray(tx.CallData),
CallData: &tx.CallData,
Fee: utils.BigInt(tx.Fee),
TTL: tx.TTL,
}
Expand Down
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The node's `swagger.json` cannot be used out of the box.
CAVEATS
`/generations/height/{height}` has an integer inside a list, cannot be targeted, have to replace by hand
`OffChain*` `allOf` is a list, this script cannot target amounts and fees in there
3. The node replies with a Generic Transaction but specifies type: "SpendTx" instead of "SpendTxJSON", so the stock generic_tx.go does not pick it up.
2. The node replies with a Generic Transaction but specifies type: "SpendTx" instead of "SpendTxJSON", so the stock generic_tx.go does not pick it up.
TODO: investigate why Python and JS SDKs have no problem with this
`python api/generic_tx_json_fix.py generated/models/` to bulk edit all `_tx_json.go` files: their `Type()` should return "*Tx" instead of "*TxJSON"
Manually add `generic_tx.go unmarshalGenericTx()`: `case "ChannelCloseMutualTxJSON": add "ChannelCloseMutualTx"` etc for other Tx types
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 3 additions & 26 deletions generated/models/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions generated/models/byte_code.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d365f8

Please sign in to comment.