punm parser
This commit is contained in:
46
budget.go
Normal file
46
budget.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package pump_parser
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type setComputeData struct {
|
||||
Units uint64
|
||||
}
|
||||
|
||||
func budgetParser(result *RawTx, instr Instruction, innerInstructions InnerInstructions, offset [2]uint, tx *Tx) ([2]uint, error) {
|
||||
if offset[1] != 0 {
|
||||
return increaseOffset(offset), nil
|
||||
}
|
||||
decode := result.Transaction.Message.Instructions[offset[0]].Data
|
||||
discriminator := decode[0]
|
||||
|
||||
switch discriminator {
|
||||
case setComputeUnitLimitDiscriminator:
|
||||
return computeUnitLimitParser(result, offset, tx, decode[1:])
|
||||
case setComputeUnitPriceDiscriminator:
|
||||
return computeUnitPriceParser(result, offset, tx, decode[1:])
|
||||
default:
|
||||
return increaseOffset(offset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func computeUnitLimitParser(_ *RawTx, offset [2]uint, _ *Tx, decodedData []byte) ([2]uint, error) {
|
||||
if len(decodedData) < 8 {
|
||||
return increaseOffset(offset), nil
|
||||
}
|
||||
return increaseOffset(offset), nil
|
||||
}
|
||||
|
||||
func computeUnitPriceParser(_ *RawTx, offset [2]uint, tx *Tx, decodedData []byte) ([2]uint, error) {
|
||||
if len(decodedData) < 8 {
|
||||
return increaseOffset(offset), nil
|
||||
}
|
||||
|
||||
cuPrice := binary.LittleEndian.Uint64(decodedData[:8])
|
||||
tx.CUPrice = decimal.NewFromInt(int64(cuPrice)).Div(decimal.NewFromInt(1000000)) // cu decimals
|
||||
|
||||
return increaseOffset(offset), nil
|
||||
}
|
||||
Reference in New Issue
Block a user