mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 03:22:18 +00:00
bbb3cc978f
* deploy_cairo_smartcontract * deploy_cairo_smartcontract / 2 Add new transaction type for cairo and vm factory * starknet_getcode * deploy_cairo_smartcontract / 3 * deploy_cairo_smartcontract / 4 * deploy_cairo_smartcontract / 5 Co-authored-by: Aleksandr Borodulin <a.borodulin@axioma.lv>
48 lines
1.2 KiB
Go
48 lines
1.2 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"
|
|
)
|
|
|
|
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])
|
|
}
|
|
|
|
return common.Hash{}, err
|
|
}
|