Skip to content

Commit

Permalink
[GraphQL] Serialize bcs bytes of TransactionData instead of `Sender…
Browse files Browse the repository at this point in the history
…SignedData` (#19768)

## Description 

This PR modifies which data is serialized to bcs for `TransactionBlock`
type. Instead of serializing to bcs `SenderSignedData`, which includes
signatures and intent message, it only serializes the transaction data.

## Test plan 

Existing tests

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [x] GraphQL: The `bcs` field of `TransactionBlock` has new data.
Instead of serializing to `bcs` from `SenderSignedData`, which includes
signatures and intent message, it only serializes the `TransactionData`
object. Note that this breaks the semantics compared to previous JSON RPC which serialized the intent and signatures. `TransactionData` only includes tx data, but no signatures or intent.
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
stefan-mysten authored Oct 11, 2024
1 parent 54dc4d0 commit 43fdf00
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crates/sui-graphql-rpc/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4226,7 +4226,7 @@ type TransactionBlock {
"""
expiration: Epoch
"""
Serialized form of this transaction's `SenderSignedData`, BCS serialized and Base64 encoded.
Serialized form of this transaction's `TransactionData`, BCS serialized and Base64 encoded.
"""
bcs: Base64
}
Expand Down
17 changes: 9 additions & 8 deletions crates/sui-graphql-rpc/src/types/transaction_block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,18 @@ impl TransactionBlock {
.extend()
}

/// Serialized form of this transaction's `SenderSignedData`, BCS serialized and Base64 encoded.
/// Serialized form of this transaction's `TransactionData`, BCS serialized and Base64 encoded.
async fn bcs(&self) -> Option<Base64> {
match &self.inner {
TransactionBlockInner::Stored { stored_tx, .. } => {
Some(Base64::from(&stored_tx.raw_transaction))
TransactionBlockInner::Stored { native, .. } => Some(Base64::from(
&bcs::to_bytes(native.transaction_data()).unwrap(),
)),
TransactionBlockInner::Executed { tx_data, .. } => Some(Base64::from(
&bcs::to_bytes(tx_data.transaction_data()).unwrap(),
)),
TransactionBlockInner::DryRun { tx_data, .. } => {
Some(Base64::from(&bcs::to_bytes(tx_data).unwrap()))
}
TransactionBlockInner::Executed { tx_data, .. } => {
bcs::to_bytes(&tx_data).ok().map(Base64::from)
}
// Dry run transaction does not have signatures so no sender signed data.
TransactionBlockInner::DryRun { .. } => None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-graphql-rpc/staging.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4226,7 +4226,7 @@ type TransactionBlock {
"""
expiration: Epoch
"""
Serialized form of this transaction's `SenderSignedData`, BCS serialized and Base64 encoded.
Serialized form of this transaction's `TransactionData`, BCS serialized and Base64 encoded.
"""
bcs: Base64
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4230,7 +4230,7 @@ type TransactionBlock {
"""
expiration: Epoch
"""
Serialized form of this transaction's `SenderSignedData`, BCS serialized and Base64 encoded.
Serialized form of this transaction's `TransactionData`, BCS serialized and Base64 encoded.
"""
bcs: Base64
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4230,7 +4230,7 @@ type TransactionBlock {
"""
expiration: Epoch
"""
Serialized form of this transaction's `SenderSignedData`, BCS serialized and Base64 encoded.
Serialized form of this transaction's `TransactionData`, BCS serialized and Base64 encoded.
"""
bcs: Base64
}
Expand Down
13 changes: 8 additions & 5 deletions sdk/graphql-transport/src/mappers/transaction-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export function mapGraphQLTransactionBlockToRpcTransactionBlock(
transaction:
transactionBlock.rawTransaction &&
mapTransactionBlockToInput(
bcs.SenderSignedData.parse(fromBase64(transactionBlock.rawTransaction))[0],
bcs.TransactionData.parse(fromBase64(transactionBlock.rawTransaction)),
transactionBlock.signatures,
),
}
: {}),
Expand Down Expand Up @@ -169,10 +170,12 @@ function mapObjectChanges(
}

export function mapTransactionBlockToInput(
data: typeof bcs.SenderSignedTransaction.$inferType,
data: typeof bcs.TransactionData.$inferType,
signatures: any[] | null | undefined,
): SuiTransactionBlock | null {
const txData = data.intentMessage.value.V1;

const txData = data.V1;
console.log('Signatures:', signatures);
const sigs: string[] = (signatures ?? []).filter((sig): sig is string => typeof sig === 'string');
const programableTransaction =
'ProgrammableTransaction' in txData.kind ? txData.kind.ProgrammableTransaction : null;

Expand All @@ -181,7 +184,7 @@ export function mapTransactionBlockToInput(
}

return {
txSignatures: data.txSignatures,
txSignatures: sigs,
data: {
gasData: {
budget: txData.gasData.budget,
Expand Down
16 changes: 8 additions & 8 deletions sdk/graphql-transport/test/compatability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('GraphQL SuiClient compatibility', () => {
// TODO inputs missing valueType
showInput: false,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
});

Expand All @@ -380,7 +380,7 @@ describe('GraphQL SuiClient compatibility', () => {
// TODO inputs missing valueType
showInput: false,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
});

Expand All @@ -397,7 +397,7 @@ describe('GraphQL SuiClient compatibility', () => {
// TODO inputs missing valueType
showInput: false,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
})) as SuiTransactionBlockResponse & { rawEffects: unknown };
const graphQLTransactionBlock = await graphQLClient!.getTransactionBlock({
Expand All @@ -408,7 +408,7 @@ describe('GraphQL SuiClient compatibility', () => {
// TODO inputs missing valueType
showInput: false,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
});

Expand All @@ -426,7 +426,7 @@ describe('GraphQL SuiClient compatibility', () => {
// TODO inputs missing valueType
showInput: false,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
});
const [graphQLTransactionBlock] = await graphQLClient!.multiGetTransactionBlocks({
Expand All @@ -439,7 +439,7 @@ describe('GraphQL SuiClient compatibility', () => {
// TODO inputs missing valueType
showInput: false,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
});

Expand Down Expand Up @@ -589,7 +589,7 @@ describe('GraphQL SuiClient compatibility', () => {
showEvents: true,
showInput: true,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
});

Expand All @@ -604,7 +604,7 @@ describe('GraphQL SuiClient compatibility', () => {
showEvents: true,
showInput: true,
showObjectChanges: true,
showRawInput: true,
showRawInput: false,
},
})) as SuiTransactionBlockResponse & { rawEffects: unknown };

Expand Down

0 comments on commit 43fdf00

Please sign in to comment.