Skip to content

Commit

Permalink
fix: TransactionRecordQuery should allow node precheck code of 0 fi…
Browse files Browse the repository at this point in the history
…nish the query if we're getting cost
  • Loading branch information
janaakhterov committed Apr 8, 2021
1 parent 9aef38a commit 53f7874
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 41 deletions.
4 changes: 0 additions & 4 deletions transaction_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func TransactionIDGenerate(accountID AccountID) TransactionID {
return TransactionID{&accountID, &validStart, false}
}

func TransactionIDWithNonce(nonce []byte) TransactionID {
return TransactionID{nil, nil, false}
}

// NewTransactionIDWithValidStart constructs a new Transaction id struct with the provided AccountID and the valid start
// time set to a provided time.
func NewTransactionIDWithValidStart(accountID AccountID, validStart time.Time) TransactionID {
Expand Down
21 changes: 1 addition & 20 deletions transaction_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,10 @@ import (

func TestTransactionID_Execute(t *testing.T) {
txID := TransactionIDGenerate(AccountID{0, 0, 3})

txID = txID.SetScheduled(true)

println(txID.String())

txID2 := TransactionIDWithNonce([]byte("bam"))

txID2 = txID2.SetScheduled(true)

txID2.AccountID = &AccountID{0, 0, 3}

println(txID2.String())

}

func TestTransactionIDFromString_Execute(t *testing.T) {
txID, err := TransactionIdFromString("[email protected]?scheduled")
_, err := TransactionIdFromString("[email protected]?scheduled")
assert.NoError(t, err)

println(txID.String())

txID2, err := TransactionIdFromString("62616d?scheduled")
assert.NoError(t, err)

println(txID2.String())
}
30 changes: 15 additions & 15 deletions transaction_receipt_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ func Test_Receipt_Transaction(t *testing.T) {
_, err = resp.GetReceipt(client)
assert.NoError(t, err)

record, err := resp.GetRecord(client)
_, err = resp.GetRecord(client)
assert.NoError(t, err)

accountID := *record.Receipt.AccountID
assert.NotNil(t, accountID)
// accountID := *record.Receipt.AccountID
// assert.NotNil(t, accountID)

transaction, err := NewAccountDeleteTransaction().
SetNodeAccountIDs([]AccountID{resp.NodeID}).
SetAccountID(accountID).
SetTransferAccountID(client.GetOperatorAccountID()).
FreezeWith(client)
assert.NoError(t, err)
// transaction, err := NewAccountDeleteTransaction().
// SetNodeAccountIDs([]AccountID{resp.NodeID}).
// SetAccountID(accountID).
// SetTransferAccountID(client.GetOperatorAccountID()).
// FreezeWith(client)
// assert.NoError(t, err)

resp, err = transaction.
Sign(newKey).
Execute(client)
assert.NoError(t, err)
// resp, err = transaction.
// Sign(newKey).
// Execute(client)
// assert.NoError(t, err)

_, err = resp.GetReceipt(client)
assert.NoError(t, err)
// _, err = resp.GetReceipt(client)
// assert.NoError(t, err)
}
12 changes: 10 additions & 2 deletions transaction_record_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,23 @@ func (query *TransactionRecordQuery) GetCost(client *Client) (Hbar, error) {
}

cost := int64(resp.query.GetTransactionGetRecord().Header.Cost)
return HbarFromTinybar(cost), nil
if cost < 25 {
return HbarFromTinybar(25), nil
} else {
return HbarFromTinybar(cost), nil
}
}

func transactionRecordQuery_shouldRetry(request request, response response) executionState {
switch Status(response.query.GetTransactionGetRecord().GetHeader().GetNodeTransactionPrecheckCode()) {
case StatusPlatformTransactionNotCreated, StatusBusy, StatusUnknown, StatusReceiptNotFound, StatusRecordNotFound:
return executionStateRetry
case StatusOk:
break
if request.query.pb.GetTransactionGetRecord().GetHeader().ResponseType == proto.ResponseType_COST_ANSWER {
return executionStateFinished
} else {
break
}
default:
return executionStateError
}
Expand Down

0 comments on commit 53f7874

Please sign in to comment.