Skip to content

Commit

Permalink
Merge pull request #4760 from 2opremio/txnbuild-auth-next
Browse files Browse the repository at this point in the history
txnbuild: Add soroban auth next to txnbuild
  • Loading branch information
sreuland authored Feb 8, 2023
2 parents 8c3f4c0 + 0950060 commit c3f7444
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions txnbuild/invoke_host_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type InvokeHostFunction struct {
Function xdr.HostFunction
Footprint xdr.LedgerFootprint
Auth []xdr.ContractAuth
SourceAccount string
}

Expand All @@ -17,6 +18,7 @@ func (f *InvokeHostFunction) BuildXDR() (xdr.Operation, error) {
xdrOp := xdr.InvokeHostFunctionOp{
Function: f.Function,
Footprint: f.Footprint,
Auth: f.Auth,
}

body, err := xdr.NewOperationBody(opType, xdrOp)
Expand All @@ -37,6 +39,7 @@ func (f *InvokeHostFunction) FromXDR(xdrOp xdr.Operation) error {
}

f.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
f.Auth = result.Auth
f.Footprint = result.Footprint
f.Function = result.Function

Expand Down
19 changes: 19 additions & 0 deletions txnbuild/invoke_host_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) {
Type: xdr.ScObjectTypeScoI64,
I64: &i64,
}
accountId := xdr.MustAddress("GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H")
invokeHostFunctionOp := &InvokeHostFunction{
Function: xdr.HostFunction{
Type: xdr.HostFunctionTypeHostFunctionTypeInvokeContract,
Expand All @@ -62,6 +63,24 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) {
},
},
},
Auth: []xdr.ContractAuth{
{
AddressWithNonce: &xdr.AddressWithNonce{
Address: xdr.ScAddress{
Type: xdr.ScAddressTypeScAddressTypeAccount,
AccountId: &accountId,
},
Nonce: 0,
},
RootInvocation: xdr.AuthorizedInvocation{
ContractId: xdr.Hash{0xaa, 0xbb},
FunctionName: "foo",
Args: nil,
SubInvocations: nil,
},
SignatureArgs: nil,
},
},
Footprint: xdr.LedgerFootprint{
ReadOnly: []xdr.LedgerKey{
{
Expand Down

0 comments on commit c3f7444

Please sign in to comment.