Skip to content

Commit

Permalink
rpcv03_Broadcast_Declare
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 22, 2023
1 parent c049339 commit a555917
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contracts/contractsv02.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (p *RPCProvider) declareAndWaitWithWallet(ctx context.Context, compiledClas
if err != nil {
return nil, err
}
tx, err := provider.AddDeclareTransaction(ctx, rpc.BroadcastedDeclareTransaction{
tx, err := provider.AddDeclareTransaction(ctx, rpc.BroadcastedDeclareTransactionV1{
BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{
Type: "DECLARE",
MaxFee: new(felt.Felt).SetUint64(10000),
Expand Down
2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type api interface {
TransactionByHash(ctx context.Context, hash *felt.Felt) (Transaction, error)
TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, error)
AddInvokeTransaction(ctx context.Context, broadcastedInvoke BroadcastedInvokeTransaction) (*AddInvokeTransactionResponse, error)
AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastedDeclareTransaction) (*AddDeclareTransactionResponse, error)
AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastedDeclareTransactionV1) (*AddDeclareTransactionResponse, error)
AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction BroadcastedDeployAccountTransaction) (*AddDeployTransactionResponse, error)
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/types_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ func (b BroadcastedInvokeV1Transaction) MarshalJSON() ([]byte, error) {
return json.Marshal(output)
}

type BroadcastedDeclareTransaction struct {
type BroadcastedDeclareTransactionV1 struct {
BroadcastedTxnCommonProperties
ContractClass DepcreatedContractClass `json:"contract_class"`
SenderAddress *felt.Felt `json:"sender_address"`
}

func (b BroadcastedDeclareTransaction) MarshalJSON() ([]byte, error) {
func (b BroadcastedDeclareTransactionV1) MarshalJSON() ([]byte, error) {
output := map[string]interface{}{}
output["type"] = "DECLARE"
if b.MaxFee != nil {
Expand Down
2 changes: 1 addition & 1 deletion rpc/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (provider *Provider) AddInvokeTransaction(ctx context.Context, broadcastedI
}

// AddDeclareTransaction submits a new class declaration transaction.
func (provider *Provider) AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastedDeclareTransaction) (*AddDeclareTransactionResponse, error) {
func (provider *Provider) AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastedDeclareTransactionV1) (*AddDeclareTransactionResponse, error) {
var result AddDeclareTransactionResponse
if err := do(ctx, provider.c, "starknet_addDeclareTransaction", &result, declareTransaction); err != nil {
if strings.Contains(err.Error(), "Invalid contract class") {
Expand Down
4 changes: 2 additions & 2 deletions rpc/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func TestDeclareTransaction(t *testing.T) {
t.Fatal("should be able to read file", err)
}

var declareTx BroadcastedDeclareTransaction
var declareTx BroadcastedDeclareTransactionV1
err = json.Unmarshal(declareTxJSON, &declareTx)
require.Nil(t, err, "Error unmarshalling decalreTx")

spy := NewSpy(testConfig.provider.c)
testConfig.provider.c = spy

// To do: test transaction against client that supports RPC method (currently Sequencer uses
// "sierra_program" instead of "program" in BroadcastedDeclareTransaction
// "sierra_program" instead of "program" in BroadcastedDeclareTransactionV1
dec, err := testConfig.provider.AddDeclareTransaction(context.Background(), declareTx)
if err != nil {
require.Equal(t, err.Error(), test.ExpectedError)
Expand Down

0 comments on commit a555917

Please sign in to comment.