Skip to content

Commit

Permalink
rawtransaction: add seperate delegateMint call
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Mar 31, 2024
1 parent acb09c4 commit f53e427
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/v1/delegateassetcreation/delegateassetcreation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func deletegateAssetCreation(c *gin.Context) {
creatorAddr := common.HexToAddress(request.CreatorAddress)
abiS := signatureSeries.SignatureSeriesABI

tx, err := rawtransaction.SendRawTransaction(abiS, "delegateAssetCreation", creatorAddr, request.MetaDataHash, request.RoyaltyPercentBasisPoint)
tx, err := rawtransaction.SendRawTransactionDelegateSignature(abiS, "delegateAssetCreation", request.ContractAddress, creatorAddr, request.MetaDataHash, request.RoyaltyPercentBasisPoint)

if err != nil {
httphelper.NewInternalServerError(c, "", "failed to call %v of %v, error: %v", "delegateAssetCreation", "StoreFront", err.Error())
Expand Down
1 change: 1 addition & 0 deletions api/v1/delegateassetcreation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type DelegateAssetCreationRequest struct {
CreatorAddress string `json:"creatorAddress" binding:"required,hexadecimal"`
MetaDataHash string `json:"metaDataHash" binding:"required"`
RoyaltyPercentBasisPoint *big.Int `json:"royaltyPercentBasisPoint" binding:"required"`
ContractAddress string `json:"contractAddress" binding:"required"`
}

type DelegateAssetCreationPayload struct {
Expand Down
80 changes: 80 additions & 0 deletions config/smartcontract/rawtransaction/rawtransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,83 @@ func SendRawTransaction(abiS string, method string, args ...interface{}) (*types
}
return signedTx, nil
}

func SendRawTransactionDelegateSignature(abiS string, method string, address string, args ...interface{}) (*types.Transaction, error) {

abiP, err := abi.JSON(strings.NewReader(abiS))
if err != nil {
logwrapper.Errorf("failed to parse JSON abi, error %v", err)
return nil, err
}
client, err := smartcontract.GetClient()
if err != nil {
return nil, err
}
mnemonic := envconfig.EnvVars.MNEMONIC
privateKey, publicKey, _, err := ethwallet.HdWallet(mnemonic) // Verify: https://iancoleman.io/bip39/
if err != nil {
logwrapper.Errorf("failed to get private and public key from mnemonic, error %v", err.Error())
return nil, err
}

nonce, err := client.PendingNonceAt(context.Background(), crypto.PubkeyToAddress(*publicKey))
if err != nil {
logwrapper.Warnf("failed to get nonce")
return nil, err
}
envContractAddress := address

toAddress := common.HexToAddress(envContractAddress)

chainID, err := client.NetworkID(context.Background())
if err != nil {
logwrapper.Errorf("failed to call client.NetworkID, error: %v", err.Error())
return nil, err
}

bytesData, err := abiP.Pack(method, args...)
if err != nil {
logwrapper.Errorf("failed to pack trasaction of method %v, error: %v", method, err)
return nil, err
}

logwrapper.Infof("nonce is %v", nonce)

maxPriorityFeePerGas, err := client.SuggestGasTipCap(context.Background())
if err != nil {
logwrapper.Errorf("failed to suggestGasTipCap, error %v", err)
return nil, err
}
config := &params.ChainConfig{
ChainID: big.NewInt(80001),
}
bn, _ := client.BlockNumber(context.Background())

bignumBn := big.NewInt(0).SetUint64(bn)
blk, _ := client.BlockByNumber(context.Background(), bignumBn)
baseFee := misc.CalcBaseFee(config, blk.Header())
big2 := big.NewInt(2)
mulRes := big.NewInt(0).Mul(baseFee, big2)
maxFeePerGas := big.NewInt(0).Add(mulRes, maxPriorityFeePerGas)
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: chainID,
Nonce: nonce,
GasFeeCap: maxFeePerGas,
GasTipCap: maxPriorityFeePerGas,
Gas: 310000,
To: &toAddress,
Data: bytesData,
})
signedTx, err := types.SignTx(tx, types.NewLondonSigner(chainID), privateKey)
if err != nil {
logwrapper.Errorf("failed to sign trasaction %v, error: %v", tx, err.Error())
return nil, err
}

err = client.SendTransaction(context.TODO(), signedTx)
if err != nil {
logwrapper.Error("failed to send trasaction, error: ", err)
return nil, err
}
return signedTx, nil
}

0 comments on commit f53e427

Please sign in to comment.