-
Notifications
You must be signed in to change notification settings - Fork 18
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
new core-go #465
base: rc/v1.7.next1
Are you sure you want to change the base?
new core-go #465
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ const ( | |
UrlParameterWithAlteredAccounts = "withAlteredAccounts" | ||
// UrlParameterWithKeys represents the name of an URL parameter | ||
UrlParameterWithKeys = "withKeys" | ||
// UrlParameterWithRelayedTxHash represents the name of an URL parameter | ||
UrlParameterWithRelayedTxHash = "withRelayedTxHash" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the |
||
) | ||
|
||
// BlockQueryOptions holds options for block queries | ||
|
@@ -67,7 +69,8 @@ type HyperblockQueryOptions struct { | |
|
||
// TransactionQueryOptions holds options for transaction queries | ||
type TransactionQueryOptions struct { | ||
WithResults bool | ||
WithResults bool | ||
WithRelayedTxHash string | ||
} | ||
|
||
// TransactionSimulationOptions holds options for transaction simulation requests | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,16 +359,99 @@ func (tp *TransactionProcessor) TransactionCostRequest(tx *data.Transaction) (*d | |
} | ||
|
||
// GetTransaction should return a transaction from observer | ||
func (tp *TransactionProcessor) GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) { | ||
tx, err := tp.getTxFromObservers(txHash, requestTypeFullHistoryNodes, withResults) | ||
func (tp *TransactionProcessor) GetTransaction(txHash string, withResults bool, withRelayedTxHash string) (*transaction.ApiTransactionResult, error) { | ||
txHashToGetFromObservers := txHash | ||
|
||
// if the relayed tx hash was provided, this one should be requested from observers | ||
innerTxRequested := len(withRelayedTxHash) == len(txHash) | ||
if innerTxRequested { | ||
txHashToGetFromObservers = withRelayedTxHash | ||
} | ||
|
||
tx, err := tp.getTxFromObservers(txHashToGetFromObservers, requestTypeFullHistoryNodes, withResults) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tx.HyperblockNonce = tx.NotarizedAtDestinationInMetaNonce | ||
tx.HyperblockHash = tx.NotarizedAtDestinationInMetaHash | ||
|
||
return tx, nil | ||
if len(tx.InnerTransactions) == 0 { | ||
if innerTxRequested { | ||
return nil, fmt.Errorf("%w, requested hash %s with relayedTxHash %s, but the relayedTxHash has no inner transaction", | ||
ErrInvalidHash, txHash, withRelayedTxHash) | ||
} | ||
|
||
return tx, nil | ||
} | ||
|
||
convertRelayedTxV3ToNetworkTx(tx) | ||
|
||
// requested a relayed transaction, returning it after scrs were moved | ||
if !innerTxRequested { | ||
return tx, nil | ||
} | ||
|
||
for _, innerTx := range tx.InnerTransactions { | ||
if innerTx.Hash == txHash { | ||
return innerTx, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("%w, but the relayedTx %s has no inner transaction with hash %s", | ||
ErrInvalidHash, withRelayedTxHash, txHash) | ||
} | ||
|
||
func convertRelayedTxV3ToNetworkTx(tx *transaction.ApiTransactionResult) { | ||
movedSCRs := make(map[string]struct{}, 0) | ||
for _, innerTx := range tx.InnerTransactions { | ||
for _, scr := range tx.SmartContractResults { | ||
if isResultOfInnerTx(tx.SmartContractResults, scr, innerTx.Hash) { | ||
innerTx.SmartContractResults = append(innerTx.SmartContractResults, scr) | ||
movedSCRs[scr.Hash] = struct{}{} | ||
} | ||
} | ||
} | ||
|
||
if len(movedSCRs) == len(tx.SmartContractResults) { | ||
// all scrs were generated by inner txs | ||
tx.SmartContractResults = make([]*transaction.ApiSmartContractResult, 0) | ||
return | ||
} | ||
|
||
numSCRsLeftForRelayer := len(tx.SmartContractResults) - len(movedSCRs) | ||
scrsForRelayer := make([]*transaction.ApiSmartContractResult, 0, numSCRsLeftForRelayer) | ||
for _, scr := range tx.SmartContractResults { | ||
_, wasMoved := movedSCRs[scr.Hash] | ||
if !wasMoved { | ||
scrsForRelayer = append(scrsForRelayer, scr) | ||
} | ||
} | ||
|
||
tx.SmartContractResults = scrsForRelayer | ||
} | ||
|
||
func isResultOfInnerTx(allScrs []*transaction.ApiSmartContractResult, currentScr *transaction.ApiSmartContractResult, innerTxHash string) bool { | ||
if currentScr.PrevTxHash == innerTxHash { | ||
return true | ||
} | ||
|
||
parentScr := getParentSCR(allScrs, currentScr.PrevTxHash) | ||
if check.IfNilReflect(parentScr) { | ||
return false | ||
} | ||
|
||
return isResultOfInnerTx(allScrs, parentScr, innerTxHash) | ||
} | ||
|
||
func getParentSCR(allScrs []*transaction.ApiSmartContractResult, hash string) *transaction.ApiSmartContractResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe can be named |
||
for _, scr := range allScrs { | ||
if scr.Hash == hash { | ||
return scr | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return nil | ||
} | ||
|
||
// GetTransactionByHashAndSenderAddress returns a transaction | ||
|
@@ -712,7 +795,7 @@ func (tp *TransactionProcessor) gatherAllLogsAndScrs(tx *transaction.ApiTransact | |
} | ||
|
||
for _, scrFromTx := range tx.SmartContractResults { | ||
scr, err := tp.GetTransaction(scrFromTx.Hash, withResults) | ||
scr, err := tp.GetTransaction(scrFromTx.Hash, withResults, "") | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("%w for scr hash %s", err, scrFromTx.Hash) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the suffix
with
(since, currently, we usewith
to dictate whether something has to be included in the response).