Skip to content
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

use atomic tx id instead of marking as block tx #80

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 18 additions & 33 deletions mapper/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,14 @@ func Transaction(
}

func crossChainTransaction(
rawIdx int,
avaxAssetID string,
tx *evm.Tx,
) ([]*types.Operation, error) {
var (
ops = []*types.Operation{}
idx = int64(rawIdx)
)
ops := []*types.Operation{}

// Prepare transaction for ID calcuation
if err := tx.Sign(evm.Codec, nil); err != nil {
return nil, err
return ops, err
}

switch t := tx.UnsignedAtomicTx.(type) {
Expand All @@ -153,14 +149,14 @@ func crossChainTransaction(
i++
}

for _, out := range t.Outs {
for idx, out := range t.Outs {
if out.AssetID.String() != avaxAssetID {
continue
}

op := &types.Operation{
ops = append(ops, &types.Operation{
OperationIdentifier: &types.OperationIdentifier{
Index: idx,
Index: int64(idx),
},
Type: OpImport,
Status: types.String(StatusSuccess),
Expand All @@ -180,19 +176,17 @@ func crossChainTransaction(
"meta": t.Metadata,
"asset_id": out.AssetID.String(),
},
}
ops = append(ops, op)
idx++
})
}
case *evm.UnsignedExportTx:
for _, in := range t.Ins {
for idx, in := range t.Ins {
if in.AssetID.String() != avaxAssetID {
continue
}

op := &types.Operation{
ops = append(ops, &types.Operation{
OperationIdentifier: &types.OperationIdentifier{
Index: idx,
Index: int64(idx),
},
Type: OpExport,
Status: types.String(StatusSuccess),
Expand All @@ -211,9 +205,7 @@ func crossChainTransaction(
"meta": t.Metadata,
"asset_id": in.AssetID.String(),
},
}
ops = append(ops, op)
idx++
})
}
default:
return nil, fmt.Errorf("unsupported transaction: %T", t)
Expand All @@ -238,26 +230,19 @@ func CrossChainTransactions(
return nil, err
}

ops := []*types.Operation{}
for _, tx := range atomicTxs {
txOps, err := crossChainTransaction(len(ops), avaxAssetID, tx)
ops, err := crossChainTransaction(avaxAssetID, tx)
if err != nil {
return nil, err
}
ops = append(ops, txOps...)
}

// TODO: migrate to using atomic transaction ID instead of marking as a block
// transaction
//
// NOTE: We need to be very careful about this because it will require
// integrators to re-index the chain to get the new result.
transactions = append(transactions, &types.Transaction{
TransactionIdentifier: &types.TransactionIdentifier{
Hash: block.Hash().String(),
},
Operations: ops,
})
transactions = append(transactions, &types.Transaction{
TransactionIdentifier: &types.TransactionIdentifier{
Hash: tx.ID().String(),
},
Operations: ops,
})
}

return transactions, nil
}
Expand Down