mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-04 01:54:28 +00:00
8e3ac8a21c
* Erigon2 upgrade 2 prototype * Latest erigon-lib * Fixes * Fix print * Fix maxSpan * Reduce maxSpan * Remove duplicate joins * TxNum * Fix resuming * first draft of history22 * Introduce historical reads * Update to erigon-lib * Update erigon-lib * Update erigon-lib * Fixes and tracing for checkChangeSets * More trace * Print account details * fix getHeader * Update to erigon-lib main * Add tracer indices and event log indices * Fix calltracer * Fix calltracer * Duplicate rpcdaemon into rpcdaemon22 * Fix tests * Fix tests * Fix tests * Update to latest erigon-lib Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
txPoolProto "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
"github.com/ledgerwatch/erigon/rlp"
|
|
"github.com/ledgerwatch/log/v3"
|
|
)
|
|
|
|
var (
|
|
ErrOnlyStarknetTx = errors.New("only support starknet transactions")
|
|
ErrOnlyContractDeploy = errors.New("only support contract creation")
|
|
)
|
|
|
|
// SendRawTransaction deploy new cairo contract
|
|
func (api *StarknetImpl) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
|
|
txn, err := types.DecodeTransaction(rlp.NewStream(bytes.NewReader(encodedTx), uint64(len(encodedTx))))
|
|
|
|
if err != nil {
|
|
return common.Hash{}, err
|
|
}
|
|
|
|
if !txn.IsStarkNet() {
|
|
return common.Hash{}, ErrOnlyStarknetTx
|
|
}
|
|
|
|
if !txn.IsContractDeploy() {
|
|
return common.Hash{}, ErrOnlyContractDeploy
|
|
}
|
|
|
|
hash := txn.Hash()
|
|
res, err := api.txPool.Add(ctx, &txPoolProto.AddRequest{RlpTxs: [][]byte{encodedTx}})
|
|
if err != nil {
|
|
return common.Hash{}, err
|
|
}
|
|
|
|
if res.Imported[0] != txPoolProto.ImportResult_SUCCESS {
|
|
return hash, fmt.Errorf("%s: %s", txPoolProto.ImportResult_name[int32(res.Imported[0])], res.Errors[0])
|
|
}
|
|
|
|
log.Info("Submitted contract creation", "hash", txn.Hash().Hex(), "nonce", txn.GetNonce(), "value", txn.GetValue())
|
|
|
|
return txn.Hash(), nil
|
|
}
|