Skip to content

Commit

Permalink
Use avax.GetAtomicUTXOs (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Jul 23, 2024
1 parent d729bc2 commit e85a44d
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1722,40 +1722,15 @@ func (vm *VM) GetAtomicUTXOs(
limit = maxUTXOsToFetch
}

addrsList := make([][]byte, addrs.Len())
for i, addr := range addrs.List() {
addrsList[i] = addr.Bytes()
}

allUTXOBytes, lastAddr, lastUTXO, err := vm.ctx.SharedMemory.Indexed(
return avax.GetAtomicUTXOs(
vm.ctx.SharedMemory,
vm.codec,
chainID,
addrsList,
startAddr.Bytes(),
startUTXOID[:],
addrs,
startAddr,
startUTXOID,
limit,
)
if err != nil {
return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("error fetching atomic UTXOs: %w", err)
}

lastAddrID, err := ids.ToShortID(lastAddr)
if err != nil {
lastAddrID = ids.ShortEmpty
}
lastUTXOID, err := ids.ToID(lastUTXO)
if err != nil {
lastUTXOID = ids.Empty
}

utxos := make([]*avax.UTXO, len(allUTXOBytes))
for i, utxoBytes := range allUTXOBytes {
utxo := &avax.UTXO{}
if _, err := vm.codec.Unmarshal(utxoBytes, utxo); err != nil {
return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("error parsing UTXO: %w", err)
}
utxos[i] = utxo
}
return utxos, lastAddrID, lastUTXOID, nil
}

// GetSpendableFunds returns a list of EVMInputs and keys (in corresponding
Expand Down

0 comments on commit e85a44d

Please sign in to comment.