From 6e8cd12b81dfcbcdb51e18b97c3cca226d828752 Mon Sep 17 00:00:00 2001 From: cyrillicw Date: Wed, 20 Oct 2021 22:05:59 +0300 Subject: [PATCH 1/7] Stream Start --- sdk/sdk.go | 11 ++ sdk/sdk_schema.go | 1 + sdk/storagev2_internal.go | 20 +-- sdk/storagev2_model.go | 20 +-- sdk/storagev2_model_test.go | 31 +++-- sdk/storagev2_schema.go | 17 ++- sdk/streamingv2.go | 7 ++ sdk/streamingv2_model.go | 13 ++ sdk/streamingv2_schema.go | 24 ++++ sdk/streamingv2_transaction.go | 119 ++++++++++++++++++ sdk/transaction_model.go | 5 + .../schema_streamingv2_transaction.fbs | 18 +++ 12 files changed, 258 insertions(+), 28 deletions(-) create mode 100644 sdk/streamingv2.go create mode 100644 sdk/streamingv2_model.go create mode 100644 sdk/streamingv2_schema.go create mode 100644 sdk/streamingv2_transaction.go create mode 100644 transactions/schemas/schema_streamingv2_transaction.fbs diff --git a/sdk/sdk.go b/sdk/sdk.go index f558a30b..8886a8f4 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -169,6 +169,7 @@ type Client struct { Contract *ContractService Metadata *MetadataService MetadataNem *MetadataNemService + StreamingV2 *StreamingV2Service } type service struct { @@ -213,6 +214,7 @@ func NewClient(httpClient *http.Client, conf *Config) *Client { c.Contract = (*ContractService)(&c.common) c.Metadata = (*MetadataService)(&c.common) c.MetadataNem = (*MetadataNemService)(&c.common) + c.StreamingV2 = (*StreamingV2Service)(&c.common) return c } @@ -925,3 +927,12 @@ func (c *Client) NewMosaicRemoveLevyTransaction(deadline *Deadline, mosaicId *Mo return tx, err } + +func (c *Client) NewStreamStartTransaction(deadline *Deadline, driveKey string, expectedUploadSize StorageSize, folder string, feedbackFeeAmount Amount) (*StreamStartTransaction, error) { + tx, err := NewStreamStartTransaction(deadline, driveKey, expectedUploadSize, folder, feedbackFeeAmount, c.config.NetworkType) + if tx != nil { + c.modifyTransaction(tx) + } + + return tx, err +} diff --git a/sdk/sdk_schema.go b/sdk/sdk_schema.go index 725fb16b..eeadc5f2 100644 --- a/sdk/sdk_schema.go +++ b/sdk/sdk_schema.go @@ -170,4 +170,5 @@ const ( ByteSize VarSize = 1 ShortSize VarSize = 2 IntSize VarSize = 4 + LongSize VarSize = 8 ) diff --git a/sdk/storagev2_internal.go b/sdk/storagev2_internal.go index 6a8a3cd8..4d86c398 100644 --- a/sdk/storagev2_internal.go +++ b/sdk/storagev2_internal.go @@ -9,10 +9,12 @@ import ( ) type activeDataModificationDTO struct { - Id hashDto `json:"id"` - Owner string `json:"owner"` - DownloadDataCdi hashDto `json:"downloadDataCdi"` - UploadSize uint64DTO `json:"uploadSize"` + Id hashDto `json:"id"` + Owner string `json:"owner"` + DownloadDataCdi hashDto `json:"downloadDataCdi"` + ExpectedUploadSize uint64DTO `json:"ExpectedUploadSize"` + ActiveUploadSize uint64DTO `json:"ActiveUploadSize"` + Folder string `json:"Folder"` } func (ref *activeDataModificationDTO) toStruct(networkType NetworkType) (*ActiveDataModification, error) { @@ -32,10 +34,12 @@ func (ref *activeDataModificationDTO) toStruct(networkType NetworkType) (*Active } return &ActiveDataModification{ - Id: id, - Owner: owner, - DownloadDataCdi: downloadDataCdi, - UploadSize: ref.UploadSize.toStruct(), + Id: id, + Owner: owner, + DownloadDataCdi: downloadDataCdi, + ExpectedUploadSize: ref.ExpectedUploadSize.toStruct(), + ActualUploadSize: ref.ActiveUploadSize.toStruct(), + Folder: ref.Folder, }, nil } diff --git a/sdk/storagev2_model.go b/sdk/storagev2_model.go index 91c60cd4..b9e2a71d 100644 --- a/sdk/storagev2_model.go +++ b/sdk/storagev2_model.go @@ -16,10 +16,12 @@ const ( ) type ActiveDataModification struct { - Id *Hash - Owner *PublicAccount - DownloadDataCdi *Hash - UploadSize StorageSize + Id *Hash + Owner *PublicAccount + DownloadDataCdi *Hash + ExpectedUploadSize StorageSize + ActualUploadSize StorageSize + Folder string } func (active *ActiveDataModification) String() string { @@ -28,12 +30,16 @@ func (active *ActiveDataModification) String() string { "Id": %s, "Owner": %s, "DownloadDataCdi": %s, - "UploadSize": %d, + "ExpectedUploadSize": %d, + "ActualUploadSize": %d, + "Folder": %s `, active.Id.String(), active.Owner.String(), active.DownloadDataCdi.String(), - active.UploadSize, + active.ExpectedUploadSize, + active.ActualUploadSize, + active.Folder, ) } @@ -171,4 +177,4 @@ type DriveClosureTransaction struct { // Replicator Offboarding Transaction type ReplicatorOffboardingTransaction struct { AbstractTransaction -} \ No newline at end of file +} diff --git a/sdk/storagev2_model_test.go b/sdk/storagev2_model_test.go index ae557f6f..049a7a1b 100644 --- a/sdk/storagev2_model_test.go +++ b/sdk/storagev2_model_test.go @@ -7,12 +7,11 @@ import ( "github.com/stretchr/testify/assert" ) - -var testActiveDataModification = &ActiveDataModification{&Hash{1}, testDriveAccount, &Hash{2}, 12} +var testActiveDataModification = &ActiveDataModification{&Hash{1}, testDriveAccount, &Hash{2}, 12, 11, "foo/bar"} var testCompletedDataModification = CompletedDataModification{testActiveDataModification, Succeeded} var testBcDrive = BcDrive{testDriveAccount, testDriveOwnerAccount, &Hash{3}, 12, 13, 14, 3, []*ActiveDataModification{testActiveDataModification}, []*CompletedDataModification{&testCompletedDataModification}} var testDriveInfov2 = &DriveInfo{&Hash{4}, false, 1, 1} -var driveInfoMap = map[string]*DriveInfo{"CFC31B3080B36BC3D59DF4AB936AC72F4DC15CE3C3E1B1EC5EA41415A4C33FEE" : testDriveInfov2} +var driveInfoMap = map[string]*DriveInfo{"CFC31B3080B36BC3D59DF4AB936AC72F4DC15CE3C3E1B1EC5EA41415A4C33FEE": testDriveInfov2} var testReplicator = Replicator{testReplicatorAccount, 2, Amount(10), "blskeys", driveInfoMap} func TestActiveDataModificationString(t *testing.T) { @@ -21,26 +20,30 @@ func TestActiveDataModificationString(t *testing.T) { "Id": 0100000000000000000000000000000000000000000000000000000000000000, "Owner": Address: [Type=168, Address=VBEHMADGUUHQ6ZMCBUYARJ44647BANFFMRKLLUPF], PublicKey: "415C7C61822B063F62A4876A6F6BA2DAAE114AB298D7AC7FC56FDBA95872C309", "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, - "UploadSize": 12, + "ExpectedUploadSize": 12, + "ActualUploadSize": 11, + "Folder": foo/bar `) assert.Equal(t, expectedResult, testActiveDataModification.String()) } -func TestCompletedDataModificationString(t *testing.T){ +func TestCompletedDataModificationString(t *testing.T) { expectedResult := fmt.Sprintf( ` "ActiveDataModification": "Id": 0100000000000000000000000000000000000000000000000000000000000000, "Owner": Address: [Type=168, Address=VBEHMADGUUHQ6ZMCBUYARJ44647BANFFMRKLLUPF], PublicKey: "415C7C61822B063F62A4876A6F6BA2DAAE114AB298D7AC7FC56FDBA95872C309", "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, - "UploadSize": 12, + "ExpectedUploadSize": 12, + "ActualUploadSize": 11, + "Folder": foo/bar , "State:" 0, `) assert.Equal(t, expectedResult, testCompletedDataModification.String()) } -func TestBcDriveString(t *testing.T){ +func TestBcDriveString(t *testing.T) { expectedResult := fmt.Sprintf( ` "BcDriveAccount": Address: [Type=168, Address=VBEHMADGUUHQ6ZMCBUYARJ44647BANFFMRKLLUPF], PublicKey: "415C7C61822B063F62A4876A6F6BA2DAAE114AB298D7AC7FC56FDBA95872C309", @@ -54,14 +57,18 @@ func TestBcDriveString(t *testing.T){ "Id": 0100000000000000000000000000000000000000000000000000000000000000, "Owner": Address: [Type=168, Address=VBEHMADGUUHQ6ZMCBUYARJ44647BANFFMRKLLUPF], PublicKey: "415C7C61822B063F62A4876A6F6BA2DAAE114AB298D7AC7FC56FDBA95872C309", "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, - "UploadSize": 12, + "ExpectedUploadSize": 12, + "ActualUploadSize": 11, + "Folder": foo/bar ], "CompletedDataModifications": [ "ActiveDataModification": "Id": 0100000000000000000000000000000000000000000000000000000000000000, "Owner": Address: [Type=168, Address=VBEHMADGUUHQ6ZMCBUYARJ44647BANFFMRKLLUPF], PublicKey: "415C7C61822B063F62A4876A6F6BA2DAAE114AB298D7AC7FC56FDBA95872C309", "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, - "UploadSize": 12, + "ExpectedUploadSize": 12, + "ActualUploadSize": 11, + "Folder": foo/bar , "State:" 0, ], @@ -69,7 +76,7 @@ func TestBcDriveString(t *testing.T){ assert.Equal(t, expectedResult, testBcDrive.String()) } -func TestDriveInfoString(t *testing.T){ +func TestDriveInfoString(t *testing.T) { expectedResult := fmt.Sprintf( ` "LastApprovedDataModificationId": 0400000000000000000000000000000000000000000000000000000000000000, @@ -80,7 +87,7 @@ func TestDriveInfoString(t *testing.T){ assert.Equal(t, expectedResult, testDriveInfov2.String()) } -func TestReplicatorString(t *testing.T){ +func TestReplicatorString(t *testing.T) { expectedResult := fmt.Sprintf( ` ReplicatorAccount: Address: [Type=168, Address=VDQPWCXBJRL5JW4VAWVWGWXDCLREERSI24PBUSUL], PublicKey: "36E7F50C8B8BC9A4FC6325B2359E0E5DB50C75A914B5292AD726FD5AE3992691", @@ -95,4 +102,4 @@ func TestReplicatorString(t *testing.T){ ], `) assert.Equal(t, expectedResult, testReplicator.String()) -} \ No newline at end of file +} diff --git a/sdk/storagev2_schema.go b/sdk/storagev2_schema.go index 018189b5..318e3684 100644 --- a/sdk/storagev2_schema.go +++ b/sdk/storagev2_schema.go @@ -62,6 +62,21 @@ func replicatorOffboardingTransactionSchema() *schema { newScalarAttribute("type", ShortSize), newArrayAttribute("maxFee", IntSize), newArrayAttribute("deadline", IntSize), + newArrayAttribute("recipient", ByteSize), + newScalarAttribute("messageSize", ShortSize), + newScalarAttribute("numMosaics", ByteSize), + newTableAttribute("message", schema{ + []schemaAttribute{ + newScalarAttribute("type", ByteSize), + newArrayAttribute("payload", ByteSize), + }, + }.schemaDefinition), + newTableArrayAttribute("mosaics", schema{ + []schemaAttribute{ + newArrayAttribute("id", IntSize), + newArrayAttribute("amount", IntSize), + }, + }.schemaDefinition), }, } -} \ No newline at end of file +} diff --git a/sdk/streamingv2.go b/sdk/streamingv2.go new file mode 100644 index 00000000..d6549f14 --- /dev/null +++ b/sdk/streamingv2.go @@ -0,0 +1,7 @@ +// Copyright 2021 ProximaX Limited. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package sdk + +type StreamingV2Service service diff --git a/sdk/streamingv2_model.go b/sdk/streamingv2_model.go new file mode 100644 index 00000000..4ce33e25 --- /dev/null +++ b/sdk/streamingv2_model.go @@ -0,0 +1,13 @@ +// Copyright 2021 ProximaX Limited. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package sdk + +type StreamStartTransaction struct { + AbstractTransaction + DriveKey string + ExpectedUploadSize StorageSize + Folder string + FeedbackFeeAmount Amount +} diff --git a/sdk/streamingv2_schema.go b/sdk/streamingv2_schema.go new file mode 100644 index 00000000..da9df10d --- /dev/null +++ b/sdk/streamingv2_schema.go @@ -0,0 +1,24 @@ +// Copyright 2021 ProximaX Limited. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package sdk + +func streamStartTransactionSchema() *schema { + return &schema{ + []schemaAttribute{ + newScalarAttribute("size", IntSize), + newArrayAttribute("signature", ByteSize), + newArrayAttribute("signer", ByteSize), + newScalarAttribute("version", IntSize), + newScalarAttribute("type", ShortSize), + newArrayAttribute("maxFee", IntSize), + newArrayAttribute("deadline", IntSize), + newArrayAttribute("driveKey", ByteSize), + newScalarAttribute("expectedUploadSize", LongSize), + newScalarAttribute("folderSize", ShortSize), + newScalarAttribute("feedbackFeeAmount", LongSize), + newArrayAttribute("folder", ByteSize), + }, + } +} diff --git a/sdk/streamingv2_transaction.go b/sdk/streamingv2_transaction.go new file mode 100644 index 00000000..b4ab6480 --- /dev/null +++ b/sdk/streamingv2_transaction.go @@ -0,0 +1,119 @@ +// Copyright 2021 ProximaX Limited. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package sdk + +import ( + "encoding/hex" + flatbuffers "github.com/google/flatbuffers/go" + "github.com/proximax-storage/go-xpx-chain-sdk/transactions" +) + +func NewStreamStartTransaction( + deadline *Deadline, + driveKey string, + expectedUploadSize StorageSize, + folder string, + feedbackFeeAmount Amount, + networkType NetworkType, +) (*StreamStartTransaction, error) { + + tx := StreamStartTransaction{ + AbstractTransaction: AbstractTransaction{ + Deadline: deadline, + Version: StreamStartVersion, + Type: StreamStart, + NetworkType: networkType, + }, + DriveKey: driveKey, + ExpectedUploadSize: expectedUploadSize, + Folder: folder, + FeedbackFeeAmount: feedbackFeeAmount, + } + + return &tx, nil +} + +func (tx *StreamStartTransaction) GetAbstractTransaction() *AbstractTransaction { + return &tx.AbstractTransaction +} + +func (tx *StreamStartTransaction) String() string { + return "" +} + +func (tx *StreamStartTransaction) Bytes() ([]byte, error) { + builder := flatbuffers.NewBuilder(0) + + bytes := []byte(tx.Folder) + fp := transactions.TransactionBufferCreateByteVector(builder, bytes) + + v, signatureV, signerV, deadlineV, fV, err := tx.AbstractTransaction.generateVectors(builder) + if err != nil { + return nil, err + } + + driveKeyB, err := hex.DecodeString(tx.DriveKey) + if err != nil { + return nil, err + } + + driveKeyV := transactions.TransactionBufferCreateByteVector(builder, driveKeyB) + + transactions.StreamStartTransactionBufferStart(builder) + transactions.TransactionBufferAddSize(builder, tx.Size()) + tx.AbstractTransaction.buildVectors(builder, v, signatureV, signerV, deadlineV, fV) + + transactions.StreamStartTransactionBufferAddDriveKey(builder, driveKeyV) + transactions.StreamStartTransactionBufferAddExpectedUploadSize(builder, uint64(tx.ExpectedUploadSize)) + transactions.StreamStartTransactionBufferAddFolderSize(builder, uint16(tx.FolderSize())) + + transactions.StreamStartTransactionBufferAddFolder(builder, fp) + + transactions.StreamStartTransactionBufferAddFeedbackFeeAmount(builder, uint64(tx.FeedbackFeeAmount)) + + t := transactions.StreamStartTransactionBufferEnd(builder) + builder.Finish(t) + + return streamStartTransactionSchema().serialize(builder.FinishedBytes()), nil +} + +func (tx *StreamStartTransaction) Size() int { + return StreamStartHeaderSize + tx.FolderSize() +} + +func (tx *StreamStartTransaction) FolderSize() int { + return len(tx.Folder) +} + +type streamStartTransactionDTO struct { + Tx struct { + abstractTransactionDTO + DriveKey string `json:"driveKey"` + ExpectedUploadSize StorageSize `json:"blsKey"` + Folder string `json:"folder"` + FeedbackFeeAmount Amount `json:"feedbackFeeAmount"` + } `json:"transaction"` + TDto transactionInfoDTO `json:"meta"` +} + +func (dto *streamStartTransactionDTO) toStruct(*Hash) (Transaction, error) { + info, err := dto.TDto.toStruct() + if err != nil { + return nil, err + } + + atx, err := dto.Tx.abstractTransactionDTO.toStruct(info) + if err != nil { + return nil, err + } + + return &StreamStartTransaction{ + *atx, + dto.Tx.DriveKey, + dto.Tx.ExpectedUploadSize, + dto.Tx.Folder, + dto.Tx.FeedbackFeeAmount, + }, nil +} diff --git a/sdk/transaction_model.go b/sdk/transaction_model.go index 039ea45d..5db0fd33 100644 --- a/sdk/transaction_model.go +++ b/sdk/transaction_model.go @@ -2787,6 +2787,7 @@ const ( ReplicatorOnboardingHeaderSize = TransactionHeaderSize + AmountSize + BlsKeySize PrepareBcDriveHeaderSize = TransactionHeaderSize + StorageSizeSize + AmountSize + 2 DriveClosureHeaderSize = TransactionHeaderSize + KeySize + StreamStartHeaderSize = TransactionHeaderSize + KeySize + StorageSizeSize + MessageSizeSize + AmountSize ) type EntityType uint16 @@ -2852,6 +2853,7 @@ const ( DataModificationCancel EntityType = 0x4562 ReplicatorOnboarding EntityType = 0x4662 DriveClosure EntityType = 0x4E62 + StreamStart EntityType = 0x4167 ) func (t EntityType) String() string { @@ -2918,6 +2920,7 @@ const ( DataModificationCancelVersion EntityVersion = 1 DownloadVersion EntityVersion = 1 DriveClosureVersion EntityVersion = 1 + StreamStartVersion EntityVersion = 1 ) type AccountLinkAction uint8 @@ -3189,6 +3192,8 @@ func MapTransaction(b *bytes.Buffer, generationHash *Hash) (Transaction, error) dto = &driveClosureTransactionDTO{} case ReplicatorOffboarding: dto = &replicatorOffboardingTransactionDTO{} + case StreamStart: + dto = &streamStartTransactionDTO{} } return dtoToTransaction(b, dto, generationHash) diff --git a/transactions/schemas/schema_streamingv2_transaction.fbs b/transactions/schemas/schema_streamingv2_transaction.fbs new file mode 100644 index 00000000..ebfe5d44 --- /dev/null +++ b/transactions/schemas/schema_streamingv2_transaction.fbs @@ -0,0 +1,18 @@ +namespace Catapult.Buffers; + +table StreamStartTransactionBuffer { + size: uint; + signature: [ubyte]; + signer: [ubyte]; + version: uint; + type: ushort; + maxFee: [uint]; + deadline: [uint]; + driveKey: [ubyte]; + expectedUploadSize: uint64; + folderSize: ushort; + feedbackFeeAmount: uint64; + folder: [ubyte]; +} + +root_type StreamStartTransactionBuffer; \ No newline at end of file From e85efb155979832e078d93ea398ce775e711d543 Mon Sep 17 00:00:00 2001 From: cyrillicw Date: Wed, 20 Oct 2021 22:27:23 +0300 Subject: [PATCH 2/7] Stream Start Buffer --- .../streamingv2_transaction_buffer.go | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 transactions/streamingv2_transaction_buffer.go diff --git a/transactions/streamingv2_transaction_buffer.go b/transactions/streamingv2_transaction_buffer.go new file mode 100644 index 00000000..17645ccb --- /dev/null +++ b/transactions/streamingv2_transaction_buffer.go @@ -0,0 +1,355 @@ +// Code generated by the FlatBuffers compiler. DO NOT EDIT. + +package transactions + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) + +type StreamStartTransactionBuffer struct { + _tab flatbuffers.Table +} + +func GetRootAsStreamStartTransactionBuffer(buf []byte, offset flatbuffers.UOffsetT) *StreamStartTransactionBuffer { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &StreamStartTransactionBuffer{} + x.Init(buf, n+offset) + return x +} + +func GetSizePrefixedRootAsStreamStartTransactionBuffer(buf []byte, offset flatbuffers.UOffsetT) *StreamStartTransactionBuffer { + n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) + x := &StreamStartTransactionBuffer{} + x.Init(buf, n+offset+flatbuffers.SizeUint32) + return x +} + +func (rcv *StreamStartTransactionBuffer) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *StreamStartTransactionBuffer) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *StreamStartTransactionBuffer) Size() uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.GetUint32(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateSize(n uint32) bool { + return rcv._tab.MutateUint32Slot(4, n) +} + +func (rcv *StreamStartTransactionBuffer) Signature(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) SignatureLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) SignatureBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamStartTransactionBuffer) MutateSignature(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamStartTransactionBuffer) Signer(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) SignerLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) SignerBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamStartTransactionBuffer) MutateSigner(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamStartTransactionBuffer) Version() uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + return rcv._tab.GetUint32(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateVersion(n uint32) bool { + return rcv._tab.MutateUint32Slot(10, n) +} + +func (rcv *StreamStartTransactionBuffer) Type() uint16 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(12)) + if o != 0 { + return rcv._tab.GetUint16(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateType(n uint16) bool { + return rcv._tab.MutateUint16Slot(12, n) +} + +func (rcv *StreamStartTransactionBuffer) MaxFee(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MaxFeeLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateMaxFee(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamStartTransactionBuffer) Deadline(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) DeadlineLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateDeadline(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamStartTransactionBuffer) DriveKey(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) DriveKeyLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) DriveKeyBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamStartTransactionBuffer) MutateDriveKey(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamStartTransactionBuffer) ExpectedUploadSize() uint64 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + return rcv._tab.GetUint64(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateExpectedUploadSize(n uint64) bool { + return rcv._tab.MutateUint64Slot(20, n) +} + +func (rcv *StreamStartTransactionBuffer) FolderSize() uint16 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + return rcv._tab.GetUint16(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateFolderSize(n uint16) bool { + return rcv._tab.MutateUint16Slot(22, n) +} + +func (rcv *StreamStartTransactionBuffer) FeedbackFeeAmount() uint64 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + return rcv._tab.GetUint64(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateFeedbackFeeAmount(n uint64) bool { + return rcv._tab.MutateUint64Slot(24, n) +} + +func (rcv *StreamStartTransactionBuffer) Folder(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) FolderLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) FolderBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamStartTransactionBuffer) MutateFolder(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func StreamStartTransactionBufferStart(builder *flatbuffers.Builder) { + builder.StartObject(12) +} +func StreamStartTransactionBufferAddSize(builder *flatbuffers.Builder, size uint32) { + builder.PrependUint32Slot(0, size, 0) +} +func StreamStartTransactionBufferAddSignature(builder *flatbuffers.Builder, signature flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(signature), 0) +} +func StreamStartTransactionBufferStartSignatureVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamStartTransactionBufferAddSigner(builder *flatbuffers.Builder, signer flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(signer), 0) +} +func StreamStartTransactionBufferStartSignerVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamStartTransactionBufferAddVersion(builder *flatbuffers.Builder, version uint32) { + builder.PrependUint32Slot(3, version, 0) +} +func StreamStartTransactionBufferAddType(builder *flatbuffers.Builder, type_ uint16) { + builder.PrependUint16Slot(4, type_, 0) +} +func StreamStartTransactionBufferAddMaxFee(builder *flatbuffers.Builder, maxFee flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(5, flatbuffers.UOffsetT(maxFee), 0) +} +func StreamStartTransactionBufferStartMaxFeeVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamStartTransactionBufferAddDeadline(builder *flatbuffers.Builder, deadline flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(6, flatbuffers.UOffsetT(deadline), 0) +} +func StreamStartTransactionBufferStartDeadlineVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamStartTransactionBufferAddDriveKey(builder *flatbuffers.Builder, driveKey flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(7, flatbuffers.UOffsetT(driveKey), 0) +} +func StreamStartTransactionBufferStartDriveKeyVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamStartTransactionBufferAddExpectedUploadSize(builder *flatbuffers.Builder, expectedUploadSize uint64) { + builder.PrependUint64Slot(8, expectedUploadSize, 0) +} +func StreamStartTransactionBufferAddFolderSize(builder *flatbuffers.Builder, folderSize uint16) { + builder.PrependUint16Slot(9, folderSize, 0) +} +func StreamStartTransactionBufferAddFeedbackFeeAmount(builder *flatbuffers.Builder, feedbackFeeAmount uint64) { + builder.PrependUint64Slot(10, feedbackFeeAmount, 0) +} +func StreamStartTransactionBufferAddFolder(builder *flatbuffers.Builder, folder flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(11, flatbuffers.UOffsetT(folder), 0) +} +func StreamStartTransactionBufferStartFolderVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamStartTransactionBufferEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} From 8debd26f5e992db6cd8a9107121f7e8e3936ffa7 Mon Sep 17 00:00:00 2001 From: kyrylo Date: Thu, 21 Oct 2021 16:27:45 +0300 Subject: [PATCH 3/7] Stream Start DTO repair --- sdk/streamingv2_transaction.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sdk/streamingv2_transaction.go b/sdk/streamingv2_transaction.go index b4ab6480..d8b607f3 100644 --- a/sdk/streamingv2_transaction.go +++ b/sdk/streamingv2_transaction.go @@ -90,10 +90,10 @@ func (tx *StreamStartTransaction) FolderSize() int { type streamStartTransactionDTO struct { Tx struct { abstractTransactionDTO - DriveKey string `json:"driveKey"` - ExpectedUploadSize StorageSize `json:"blsKey"` - Folder string `json:"folder"` - FeedbackFeeAmount Amount `json:"feedbackFeeAmount"` + DriveKey string `json:"driveKey"` + ExpectedUploadSize uint64DTO `json:"expectedUploadSize"` + Folder string `json:"folder"` + FeedbackFeeAmount uint64DTO `json:"feedbackFeeAmount"` } `json:"transaction"` TDto transactionInfoDTO `json:"meta"` } @@ -109,11 +109,17 @@ func (dto *streamStartTransactionDTO) toStruct(*Hash) (Transaction, error) { return nil, err } + folderBytes, err := hex.DecodeString(dto.Tx.Folder) + if err != nil { + return nil, err + } + return &StreamStartTransaction{ *atx, dto.Tx.DriveKey, - dto.Tx.ExpectedUploadSize, - dto.Tx.Folder, - dto.Tx.FeedbackFeeAmount, + dto.Tx.ExpectedUploadSize.toStruct(), + + string(folderBytes[:]), + dto.Tx.FeedbackFeeAmount.toStruct(), }, nil } From ceed75f22859f061ccc1b41879d875167d057f8c Mon Sep 17 00:00:00 2001 From: kyrylo Date: Thu, 21 Oct 2021 17:00:27 +0300 Subject: [PATCH 4/7] ActiveDataModification DTO repair --- sdk/storagev2_internal.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sdk/storagev2_internal.go b/sdk/storagev2_internal.go index 4d86c398..b9f9a578 100644 --- a/sdk/storagev2_internal.go +++ b/sdk/storagev2_internal.go @@ -5,6 +5,7 @@ package sdk import ( + "encoding/hex" "fmt" ) @@ -13,7 +14,7 @@ type activeDataModificationDTO struct { Owner string `json:"owner"` DownloadDataCdi hashDto `json:"downloadDataCdi"` ExpectedUploadSize uint64DTO `json:"ExpectedUploadSize"` - ActiveUploadSize uint64DTO `json:"ActiveUploadSize"` + ActualUploadSize uint64DTO `json:"ActualUploadSize"` Folder string `json:"Folder"` } @@ -33,13 +34,18 @@ func (ref *activeDataModificationDTO) toStruct(networkType NetworkType) (*Active return nil, err } + folderBytes, err := hex.DecodeString(ref.Folder) + if err != nil { + return nil, err + } + return &ActiveDataModification{ Id: id, Owner: owner, DownloadDataCdi: downloadDataCdi, ExpectedUploadSize: ref.ExpectedUploadSize.toStruct(), - ActualUploadSize: ref.ActiveUploadSize.toStruct(), - Folder: ref.Folder, + ActualUploadSize: ref.ActualUploadSize.toStruct(), + Folder: string(folderBytes[:]), }, nil } From 2d4e37f31be37ec719c9456735f0ca05f433605b Mon Sep 17 00:00:00 2001 From: kyrylo Date: Thu, 21 Oct 2021 18:01:11 +0300 Subject: [PATCH 5/7] remove hex decoding in stream dto --- sdk/storagev2_internal.go | 8 +------- sdk/streamingv2_transaction.go | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/sdk/storagev2_internal.go b/sdk/storagev2_internal.go index b9f9a578..f2f415a1 100644 --- a/sdk/storagev2_internal.go +++ b/sdk/storagev2_internal.go @@ -5,7 +5,6 @@ package sdk import ( - "encoding/hex" "fmt" ) @@ -34,18 +33,13 @@ func (ref *activeDataModificationDTO) toStruct(networkType NetworkType) (*Active return nil, err } - folderBytes, err := hex.DecodeString(ref.Folder) - if err != nil { - return nil, err - } - return &ActiveDataModification{ Id: id, Owner: owner, DownloadDataCdi: downloadDataCdi, ExpectedUploadSize: ref.ExpectedUploadSize.toStruct(), ActualUploadSize: ref.ActualUploadSize.toStruct(), - Folder: string(folderBytes[:]), + Folder: ref.Folder, }, nil } diff --git a/sdk/streamingv2_transaction.go b/sdk/streamingv2_transaction.go index d8b607f3..7b5e11fa 100644 --- a/sdk/streamingv2_transaction.go +++ b/sdk/streamingv2_transaction.go @@ -109,17 +109,11 @@ func (dto *streamStartTransactionDTO) toStruct(*Hash) (Transaction, error) { return nil, err } - folderBytes, err := hex.DecodeString(dto.Tx.Folder) - if err != nil { - return nil, err - } - return &StreamStartTransaction{ *atx, dto.Tx.DriveKey, dto.Tx.ExpectedUploadSize.toStruct(), - - string(folderBytes[:]), + dto.Tx.Folder, dto.Tx.FeedbackFeeAmount.toStruct(), }, nil } From 892960e7727f2a38acfb22589889ea4bd39ebc02 Mon Sep 17 00:00:00 2001 From: kyrylo Date: Wed, 27 Oct 2021 12:14:03 +0300 Subject: [PATCH 6/7] Stream Finish --- sdk/sdk.go | 9 + sdk/storagev2_internal.go | 4 +- sdk/storagev2_model.go | 9 +- sdk/storagev2_model_test.go | 14 +- sdk/streamingv2_model.go | 10 +- sdk/streamingv2_schema.go | 26 +- sdk/streamingv2_transaction.go | 166 ++++++- sdk/transaction_model.go | 5 + .../schema_streamingv2_transaction.fbs | 25 +- .../streamingv2_transaction_buffer.go | 455 +++++++++++++++++- 10 files changed, 667 insertions(+), 56 deletions(-) diff --git a/sdk/sdk.go b/sdk/sdk.go index 8886a8f4..e3b0f3a5 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -936,3 +936,12 @@ func (c *Client) NewStreamStartTransaction(deadline *Deadline, driveKey string, return tx, err } + +func (c *Client) NewStreamFinishTransaction(deadline *Deadline, driveKey string, streamId string, actualUploadSize StorageSize, streamStructureCdi string) (*StreamFinishTransaction, error) { + tx, err := NewStreamFinishTransaction(deadline, driveKey, streamId, actualUploadSize, streamStructureCdi, c.config.NetworkType) + if tx != nil { + c.modifyTransaction(tx) + } + + return tx, err +} diff --git a/sdk/storagev2_internal.go b/sdk/storagev2_internal.go index f2f415a1..a859e413 100644 --- a/sdk/storagev2_internal.go +++ b/sdk/storagev2_internal.go @@ -14,7 +14,7 @@ type activeDataModificationDTO struct { DownloadDataCdi hashDto `json:"downloadDataCdi"` ExpectedUploadSize uint64DTO `json:"ExpectedUploadSize"` ActualUploadSize uint64DTO `json:"ActualUploadSize"` - Folder string `json:"Folder"` + FolderName string `json:"FolderName"` } func (ref *activeDataModificationDTO) toStruct(networkType NetworkType) (*ActiveDataModification, error) { @@ -39,7 +39,7 @@ func (ref *activeDataModificationDTO) toStruct(networkType NetworkType) (*Active DownloadDataCdi: downloadDataCdi, ExpectedUploadSize: ref.ExpectedUploadSize.toStruct(), ActualUploadSize: ref.ActualUploadSize.toStruct(), - Folder: ref.Folder, + FolderName: ref.FolderName, }, nil } diff --git a/sdk/storagev2_model.go b/sdk/storagev2_model.go index b9e2a71d..b7d51538 100644 --- a/sdk/storagev2_model.go +++ b/sdk/storagev2_model.go @@ -21,7 +21,8 @@ type ActiveDataModification struct { DownloadDataCdi *Hash ExpectedUploadSize StorageSize ActualUploadSize StorageSize - Folder string + FolderName string + ReadyForApproval bool } func (active *ActiveDataModification) String() string { @@ -32,14 +33,16 @@ func (active *ActiveDataModification) String() string { "DownloadDataCdi": %s, "ExpectedUploadSize": %d, "ActualUploadSize": %d, - "Folder": %s + "FolderName": %s, + "ReadyForApproval": %v `, active.Id.String(), active.Owner.String(), active.DownloadDataCdi.String(), active.ExpectedUploadSize, active.ActualUploadSize, - active.Folder, + active.FolderName, + active.ReadyForApproval, ) } diff --git a/sdk/storagev2_model_test.go b/sdk/storagev2_model_test.go index 049a7a1b..336c2702 100644 --- a/sdk/storagev2_model_test.go +++ b/sdk/storagev2_model_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) -var testActiveDataModification = &ActiveDataModification{&Hash{1}, testDriveAccount, &Hash{2}, 12, 11, "foo/bar"} +var testActiveDataModification = &ActiveDataModification{&Hash{1}, testDriveAccount, &Hash{2}, 12, 11, "foo/bar", true} var testCompletedDataModification = CompletedDataModification{testActiveDataModification, Succeeded} var testBcDrive = BcDrive{testDriveAccount, testDriveOwnerAccount, &Hash{3}, 12, 13, 14, 3, []*ActiveDataModification{testActiveDataModification}, []*CompletedDataModification{&testCompletedDataModification}} var testDriveInfov2 = &DriveInfo{&Hash{4}, false, 1, 1} @@ -22,7 +22,8 @@ func TestActiveDataModificationString(t *testing.T) { "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, "ExpectedUploadSize": 12, "ActualUploadSize": 11, - "Folder": foo/bar + "FolderName": foo/bar, + "ReadyForApproval": true `) assert.Equal(t, expectedResult, testActiveDataModification.String()) } @@ -36,7 +37,8 @@ func TestCompletedDataModificationString(t *testing.T) { "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, "ExpectedUploadSize": 12, "ActualUploadSize": 11, - "Folder": foo/bar + "FolderName": foo/bar, + "ReadyForApproval": true , "State:" 0, `) @@ -59,7 +61,8 @@ func TestBcDriveString(t *testing.T) { "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, "ExpectedUploadSize": 12, "ActualUploadSize": 11, - "Folder": foo/bar + "FolderName": foo/bar, + "ReadyForApproval": true ], "CompletedDataModifications": [ "ActiveDataModification": @@ -68,7 +71,8 @@ func TestBcDriveString(t *testing.T) { "DownloadDataCdi": 0200000000000000000000000000000000000000000000000000000000000000, "ExpectedUploadSize": 12, "ActualUploadSize": 11, - "Folder": foo/bar + "FolderName": foo/bar, + "ReadyForApproval": true , "State:" 0, ], diff --git a/sdk/streamingv2_model.go b/sdk/streamingv2_model.go index 4ce33e25..0fdf8ef0 100644 --- a/sdk/streamingv2_model.go +++ b/sdk/streamingv2_model.go @@ -8,6 +8,14 @@ type StreamStartTransaction struct { AbstractTransaction DriveKey string ExpectedUploadSize StorageSize - Folder string + FolderName string FeedbackFeeAmount Amount } + +type StreamFinishTransaction struct { + AbstractTransaction + DriveKey string + StreamId string + ActualUploadSize StorageSize + StreamStructureCdi string +} diff --git a/sdk/streamingv2_schema.go b/sdk/streamingv2_schema.go index da9df10d..9b0574f7 100644 --- a/sdk/streamingv2_schema.go +++ b/sdk/streamingv2_schema.go @@ -15,10 +15,28 @@ func streamStartTransactionSchema() *schema { newArrayAttribute("maxFee", IntSize), newArrayAttribute("deadline", IntSize), newArrayAttribute("driveKey", ByteSize), - newScalarAttribute("expectedUploadSize", LongSize), - newScalarAttribute("folderSize", ShortSize), - newScalarAttribute("feedbackFeeAmount", LongSize), - newArrayAttribute("folder", ByteSize), + newArrayAttribute("expectedUploadSize", IntSize), + newScalarAttribute("folderNameSize", ShortSize), + newArrayAttribute("feedbackFeeAmount", IntSize), + newArrayAttribute("folderName", ByteSize), + }, + } +} + +func streamFinishTransactionSchema() *schema { + return &schema{ + []schemaAttribute{ + newScalarAttribute("size", IntSize), + newArrayAttribute("signature", ByteSize), + newArrayAttribute("signer", ByteSize), + newScalarAttribute("version", IntSize), + newScalarAttribute("type", ShortSize), + newArrayAttribute("maxFee", IntSize), + newArrayAttribute("deadline", IntSize), + newArrayAttribute("driveKey", ByteSize), + newArrayAttribute("streamId", ByteSize), + newArrayAttribute("actualUploadSize", IntSize), + newArrayAttribute("streamStructureCdi", ByteSize), }, } } diff --git a/sdk/streamingv2_transaction.go b/sdk/streamingv2_transaction.go index 7b5e11fa..38143642 100644 --- a/sdk/streamingv2_transaction.go +++ b/sdk/streamingv2_transaction.go @@ -6,6 +6,7 @@ package sdk import ( "encoding/hex" + "fmt" flatbuffers "github.com/google/flatbuffers/go" "github.com/proximax-storage/go-xpx-chain-sdk/transactions" ) @@ -14,7 +15,7 @@ func NewStreamStartTransaction( deadline *Deadline, driveKey string, expectedUploadSize StorageSize, - folder string, + folderName string, feedbackFeeAmount Amount, networkType NetworkType, ) (*StreamStartTransaction, error) { @@ -28,7 +29,7 @@ func NewStreamStartTransaction( }, DriveKey: driveKey, ExpectedUploadSize: expectedUploadSize, - Folder: folder, + FolderName: folderName, FeedbackFeeAmount: feedbackFeeAmount, } @@ -40,13 +41,26 @@ func (tx *StreamStartTransaction) GetAbstractTransaction() *AbstractTransaction } func (tx *StreamStartTransaction) String() string { - return "" + return fmt.Sprintf( + ` + "AbstractTransaction": %s, + "DriveKey": %s, + "ExpectedUploadSize": %d, + "FolderName": %s, + "FeedbackFeeAmount", %v, + `, + tx.AbstractTransaction.String(), + tx.DriveKey, + tx.ExpectedUploadSize, + tx.FolderName, + tx.FeedbackFeeAmount, + ) } func (tx *StreamStartTransaction) Bytes() ([]byte, error) { builder := flatbuffers.NewBuilder(0) - bytes := []byte(tx.Folder) + bytes := []byte(tx.FolderName) fp := transactions.TransactionBufferCreateByteVector(builder, bytes) v, signatureV, signerV, deadlineV, fV, err := tx.AbstractTransaction.generateVectors(builder) @@ -60,18 +74,20 @@ func (tx *StreamStartTransaction) Bytes() ([]byte, error) { } driveKeyV := transactions.TransactionBufferCreateByteVector(builder, driveKeyB) + expectedUploadSizeV := transactions.TransactionBufferCreateUint32Vector(builder, tx.ExpectedUploadSize.toArray()) + feedbackFeeAmountV := transactions.TransactionBufferCreateUint32Vector(builder, tx.FeedbackFeeAmount.toArray()) transactions.StreamStartTransactionBufferStart(builder) transactions.TransactionBufferAddSize(builder, tx.Size()) tx.AbstractTransaction.buildVectors(builder, v, signatureV, signerV, deadlineV, fV) transactions.StreamStartTransactionBufferAddDriveKey(builder, driveKeyV) - transactions.StreamStartTransactionBufferAddExpectedUploadSize(builder, uint64(tx.ExpectedUploadSize)) - transactions.StreamStartTransactionBufferAddFolderSize(builder, uint16(tx.FolderSize())) + transactions.StreamStartTransactionBufferAddExpectedUploadSize(builder, expectedUploadSizeV) + transactions.StreamStartTransactionBufferAddFolderNameSize(builder, uint16(tx.FolderNameSize())) - transactions.StreamStartTransactionBufferAddFolder(builder, fp) + transactions.StreamStartTransactionBufferAddFolderName(builder, fp) - transactions.StreamStartTransactionBufferAddFeedbackFeeAmount(builder, uint64(tx.FeedbackFeeAmount)) + transactions.StreamStartTransactionBufferAddFeedbackFeeAmount(builder, feedbackFeeAmountV) t := transactions.StreamStartTransactionBufferEnd(builder) builder.Finish(t) @@ -80,11 +96,11 @@ func (tx *StreamStartTransaction) Bytes() ([]byte, error) { } func (tx *StreamStartTransaction) Size() int { - return StreamStartHeaderSize + tx.FolderSize() + return StreamStartHeaderSize + tx.FolderNameSize() } -func (tx *StreamStartTransaction) FolderSize() int { - return len(tx.Folder) +func (tx *StreamStartTransaction) FolderNameSize() int { + return len(tx.FolderName) } type streamStartTransactionDTO struct { @@ -92,7 +108,7 @@ type streamStartTransactionDTO struct { abstractTransactionDTO DriveKey string `json:"driveKey"` ExpectedUploadSize uint64DTO `json:"expectedUploadSize"` - Folder string `json:"folder"` + FolderName string `json:"folderName"` FeedbackFeeAmount uint64DTO `json:"feedbackFeeAmount"` } `json:"transaction"` TDto transactionInfoDTO `json:"meta"` @@ -113,7 +129,131 @@ func (dto *streamStartTransactionDTO) toStruct(*Hash) (Transaction, error) { *atx, dto.Tx.DriveKey, dto.Tx.ExpectedUploadSize.toStruct(), - dto.Tx.Folder, + dto.Tx.FolderName, dto.Tx.FeedbackFeeAmount.toStruct(), }, nil } + +func NewStreamFinishTransaction( + deadline *Deadline, + driveKey string, + streamId string, + actualUploadSize StorageSize, + streamStructureCdi string, + networkType NetworkType, +) (*StreamFinishTransaction, error) { + + tx := StreamFinishTransaction{ + AbstractTransaction: AbstractTransaction{ + Deadline: deadline, + Version: StreamFinishVersion, + Type: StreamFinish, + NetworkType: networkType, + }, + DriveKey: driveKey, + StreamId: streamId, + ActualUploadSize: actualUploadSize, + StreamStructureCdi: streamStructureCdi, + } + + return &tx, nil +} + +func (tx *StreamFinishTransaction) GetAbstractTransaction() *AbstractTransaction { + return &tx.AbstractTransaction +} + +func (tx *StreamFinishTransaction) String() string { + return fmt.Sprintf( + ` + "AbstractTransaction": %s, + "DriveKey": %s, + "StreamId": %s + "ActualUploadSize": %d, + "StreamStructureCdi": %s, + `, + tx.AbstractTransaction.String(), + tx.DriveKey, + tx.StreamId, + tx.ActualUploadSize, + tx.StreamStructureCdi, + ) +} + +func (tx *StreamFinishTransaction) Bytes() ([]byte, error) { + builder := flatbuffers.NewBuilder(0) + + v, signatureV, signerV, deadlineV, fV, err := tx.AbstractTransaction.generateVectors(builder) + if err != nil { + return nil, err + } + + driveKeyB, err := hex.DecodeString(tx.DriveKey) + if err != nil { + return nil, err + } + + streamIdB, err := hex.DecodeString(tx.StreamId) + if err != nil { + return nil, err + } + + streamStructureCdi, err := hex.DecodeString(tx.StreamStructureCdi) + if err != nil { + return nil, err + } + + driveKeyV := transactions.TransactionBufferCreateByteVector(builder, driveKeyB) + streamIdV := transactions.TransactionBufferCreateByteVector(builder, streamIdB) + actualUploadSizeV := transactions.TransactionBufferCreateUint32Vector(builder, tx.ActualUploadSize.toArray()) + streamStructureCdiV := transactions.TransactionBufferCreateByteVector(builder, streamStructureCdi) + + transactions.StreamFinishTransactionBufferStart(builder) + transactions.TransactionBufferAddSize(builder, tx.Size()) + tx.AbstractTransaction.buildVectors(builder, v, signatureV, signerV, deadlineV, fV) + + transactions.StreamFinishTransactionBufferAddDriveKey(builder, driveKeyV) + transactions.StreamFinishTransactionBufferAddStreamId(builder, streamIdV) + transactions.StreamFinishTransactionBufferAddActualUploadSize(builder, actualUploadSizeV) + transactions.StreamFinishTransactionBufferAddStreamStructureCdi(builder, streamStructureCdiV) + + t := transactions.StreamFinishTransactionBufferEnd(builder) + builder.Finish(t) + + return streamFinishTransactionSchema().serialize(builder.FinishedBytes()), nil +} + +func (tx *StreamFinishTransaction) Size() int { + return StreamFinishHeaderSize +} + +type streamFinishTransactionDTO struct { + Tx struct { + abstractTransactionDTO + DriveKey string `json:"driveKey"` + StreamId string `json:"streamId"` + ActualUploadSize uint64DTO `json:"actualUploadSize"` + StreamStructureCdi string `json:"streamStructureCdi"` + } `json:"transaction"` + TDto transactionInfoDTO `json:"meta"` +} + +func (dto *streamFinishTransactionDTO) toStruct(*Hash) (Transaction, error) { + info, err := dto.TDto.toStruct() + if err != nil { + return nil, err + } + + atx, err := dto.Tx.abstractTransactionDTO.toStruct(info) + if err != nil { + return nil, err + } + + return &StreamFinishTransaction{ + *atx, + dto.Tx.DriveKey, + dto.Tx.StreamId, + dto.Tx.ActualUploadSize.toStruct(), + dto.Tx.StreamStructureCdi, + }, nil +} diff --git a/sdk/transaction_model.go b/sdk/transaction_model.go index 5db0fd33..d8e7b0c5 100644 --- a/sdk/transaction_model.go +++ b/sdk/transaction_model.go @@ -2788,6 +2788,7 @@ const ( PrepareBcDriveHeaderSize = TransactionHeaderSize + StorageSizeSize + AmountSize + 2 DriveClosureHeaderSize = TransactionHeaderSize + KeySize StreamStartHeaderSize = TransactionHeaderSize + KeySize + StorageSizeSize + MessageSizeSize + AmountSize + StreamFinishHeaderSize = TransactionHeaderSize + KeySize + Hash256 + StorageSizeSize + Hash256 ) type EntityType uint16 @@ -2854,6 +2855,7 @@ const ( ReplicatorOnboarding EntityType = 0x4662 DriveClosure EntityType = 0x4E62 StreamStart EntityType = 0x4167 + StreamFinish EntityType = 0x4267 ) func (t EntityType) String() string { @@ -2921,6 +2923,7 @@ const ( DownloadVersion EntityVersion = 1 DriveClosureVersion EntityVersion = 1 StreamStartVersion EntityVersion = 1 + StreamFinishVersion EntityVersion = 1 ) type AccountLinkAction uint8 @@ -3194,6 +3197,8 @@ func MapTransaction(b *bytes.Buffer, generationHash *Hash) (Transaction, error) dto = &replicatorOffboardingTransactionDTO{} case StreamStart: dto = &streamStartTransactionDTO{} + case StreamFinish: + dto = &streamFinishTransactionDTO{} } return dtoToTransaction(b, dto, generationHash) diff --git a/transactions/schemas/schema_streamingv2_transaction.fbs b/transactions/schemas/schema_streamingv2_transaction.fbs index ebfe5d44..325f59ff 100644 --- a/transactions/schemas/schema_streamingv2_transaction.fbs +++ b/transactions/schemas/schema_streamingv2_transaction.fbs @@ -9,10 +9,25 @@ table StreamStartTransactionBuffer { maxFee: [uint]; deadline: [uint]; driveKey: [ubyte]; - expectedUploadSize: uint64; - folderSize: ushort; - feedbackFeeAmount: uint64; - folder: [ubyte]; + expectedUploadSize: [uint]; + folderNameSize: ushort; + feedbackFeeAmount: [uint]; + folderName: [ubyte]; } -root_type StreamStartTransactionBuffer; \ No newline at end of file +table StreamFinishTransactionBuffer { + size: uint; + signature: [ubyte]; + signer: [ubyte]; + version: uint; + type: ushort; + maxFee: [uint]; + deadline: [uint]; + driveKey: [ubyte]; + streamId: [ubyte]; + actualUploadSize: [uint]; + streamStructureCdi: [ubyte]; +} + +root_type StreamStartTransactionBuffer; +root_type StreamFinishTransactionBuffer; \ No newline at end of file diff --git a/transactions/streamingv2_transaction_buffer.go b/transactions/streamingv2_transaction_buffer.go index 17645ccb..519cc650 100644 --- a/transactions/streamingv2_transaction_buffer.go +++ b/transactions/streamingv2_transaction_buffer.go @@ -223,19 +223,33 @@ func (rcv *StreamStartTransactionBuffer) MutateDriveKey(j int, n byte) bool { return false } -func (rcv *StreamStartTransactionBuffer) ExpectedUploadSize() uint64 { +func (rcv *StreamStartTransactionBuffer) ExpectedUploadSize(j int) uint32 { o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) if o != 0 { - return rcv._tab.GetUint64(o + rcv._tab.Pos) + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) } return 0 } -func (rcv *StreamStartTransactionBuffer) MutateExpectedUploadSize(n uint64) bool { - return rcv._tab.MutateUint64Slot(20, n) +func (rcv *StreamStartTransactionBuffer) ExpectedUploadSizeLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamStartTransactionBuffer) MutateExpectedUploadSize(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false } -func (rcv *StreamStartTransactionBuffer) FolderSize() uint16 { +func (rcv *StreamStartTransactionBuffer) FolderNameSize() uint16 { o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) if o != 0 { return rcv._tab.GetUint16(o + rcv._tab.Pos) @@ -243,23 +257,37 @@ func (rcv *StreamStartTransactionBuffer) FolderSize() uint16 { return 0 } -func (rcv *StreamStartTransactionBuffer) MutateFolderSize(n uint16) bool { +func (rcv *StreamStartTransactionBuffer) MutateFolderNameSize(n uint16) bool { return rcv._tab.MutateUint16Slot(22, n) } -func (rcv *StreamStartTransactionBuffer) FeedbackFeeAmount() uint64 { +func (rcv *StreamStartTransactionBuffer) FeedbackFeeAmount(j int) uint32 { o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) if o != 0 { - return rcv._tab.GetUint64(o + rcv._tab.Pos) + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) } return 0 } -func (rcv *StreamStartTransactionBuffer) MutateFeedbackFeeAmount(n uint64) bool { - return rcv._tab.MutateUint64Slot(24, n) +func (rcv *StreamStartTransactionBuffer) FeedbackFeeAmountLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 } -func (rcv *StreamStartTransactionBuffer) Folder(j int) byte { +func (rcv *StreamStartTransactionBuffer) MutateFeedbackFeeAmount(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamStartTransactionBuffer) FolderName(j int) byte { o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) if o != 0 { a := rcv._tab.Vector(o) @@ -268,7 +296,7 @@ func (rcv *StreamStartTransactionBuffer) Folder(j int) byte { return 0 } -func (rcv *StreamStartTransactionBuffer) FolderLength() int { +func (rcv *StreamStartTransactionBuffer) FolderNameLength() int { o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) if o != 0 { return rcv._tab.VectorLen(o) @@ -276,7 +304,7 @@ func (rcv *StreamStartTransactionBuffer) FolderLength() int { return 0 } -func (rcv *StreamStartTransactionBuffer) FolderBytes() []byte { +func (rcv *StreamStartTransactionBuffer) FolderNameBytes() []byte { o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) if o != 0 { return rcv._tab.ByteVector(o + rcv._tab.Pos) @@ -284,7 +312,7 @@ func (rcv *StreamStartTransactionBuffer) FolderBytes() []byte { return nil } -func (rcv *StreamStartTransactionBuffer) MutateFolder(j int, n byte) bool { +func (rcv *StreamStartTransactionBuffer) MutateFolderName(j int, n byte) bool { o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) if o != 0 { a := rcv._tab.Vector(o) @@ -335,21 +363,402 @@ func StreamStartTransactionBufferAddDriveKey(builder *flatbuffers.Builder, drive func StreamStartTransactionBufferStartDriveKeyVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1) } -func StreamStartTransactionBufferAddExpectedUploadSize(builder *flatbuffers.Builder, expectedUploadSize uint64) { - builder.PrependUint64Slot(8, expectedUploadSize, 0) +func StreamStartTransactionBufferAddExpectedUploadSize(builder *flatbuffers.Builder, expectedUploadSize flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(8, flatbuffers.UOffsetT(expectedUploadSize), 0) } -func StreamStartTransactionBufferAddFolderSize(builder *flatbuffers.Builder, folderSize uint16) { - builder.PrependUint16Slot(9, folderSize, 0) +func StreamStartTransactionBufferStartExpectedUploadSizeVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) } -func StreamStartTransactionBufferAddFeedbackFeeAmount(builder *flatbuffers.Builder, feedbackFeeAmount uint64) { - builder.PrependUint64Slot(10, feedbackFeeAmount, 0) +func StreamStartTransactionBufferAddFolderNameSize(builder *flatbuffers.Builder, folderNameSize uint16) { + builder.PrependUint16Slot(9, folderNameSize, 0) } -func StreamStartTransactionBufferAddFolder(builder *flatbuffers.Builder, folder flatbuffers.UOffsetT) { - builder.PrependUOffsetTSlot(11, flatbuffers.UOffsetT(folder), 0) +func StreamStartTransactionBufferAddFeedbackFeeAmount(builder *flatbuffers.Builder, feedbackFeeAmount flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(10, flatbuffers.UOffsetT(feedbackFeeAmount), 0) +} +func StreamStartTransactionBufferStartFeedbackFeeAmountVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) } -func StreamStartTransactionBufferStartFolderVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { +func StreamStartTransactionBufferAddFolderName(builder *flatbuffers.Builder, folderName flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(11, flatbuffers.UOffsetT(folderName), 0) +} +func StreamStartTransactionBufferStartFolderNameVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1) } func StreamStartTransactionBufferEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } + +type StreamFinishTransactionBuffer struct { + _tab flatbuffers.Table +} + +func GetRootAsStreamFinishTransactionBuffer(buf []byte, offset flatbuffers.UOffsetT) *StreamFinishTransactionBuffer { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &StreamFinishTransactionBuffer{} + x.Init(buf, n+offset) + return x +} + +func GetSizePrefixedRootAsStreamFinishTransactionBuffer(buf []byte, offset flatbuffers.UOffsetT) *StreamFinishTransactionBuffer { + n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) + x := &StreamFinishTransactionBuffer{} + x.Init(buf, n+offset+flatbuffers.SizeUint32) + return x +} + +func (rcv *StreamFinishTransactionBuffer) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *StreamFinishTransactionBuffer) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *StreamFinishTransactionBuffer) Size() uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.GetUint32(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MutateSize(n uint32) bool { + return rcv._tab.MutateUint32Slot(4, n) +} + +func (rcv *StreamFinishTransactionBuffer) Signature(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) SignatureLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) SignatureBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamFinishTransactionBuffer) MutateSignature(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) Signer(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) SignerLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) SignerBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamFinishTransactionBuffer) MutateSigner(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) Version() uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + return rcv._tab.GetUint32(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MutateVersion(n uint32) bool { + return rcv._tab.MutateUint32Slot(10, n) +} + +func (rcv *StreamFinishTransactionBuffer) Type() uint16 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(12)) + if o != 0 { + return rcv._tab.GetUint16(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MutateType(n uint16) bool { + return rcv._tab.MutateUint16Slot(12, n) +} + +func (rcv *StreamFinishTransactionBuffer) MaxFee(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MaxFeeLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MutateMaxFee(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) Deadline(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) DeadlineLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MutateDeadline(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) DriveKey(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) DriveKeyLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) DriveKeyBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamFinishTransactionBuffer) MutateDriveKey(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) StreamId(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) StreamIdLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) StreamIdBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamFinishTransactionBuffer) MutateStreamId(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) ActualUploadSize(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) ActualUploadSizeLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) MutateActualUploadSize(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamFinishTransactionBuffer) StreamStructureCdi(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) StreamStructureCdiLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamFinishTransactionBuffer) StreamStructureCdiBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamFinishTransactionBuffer) MutateStreamStructureCdi(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(24)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func StreamFinishTransactionBufferStart(builder *flatbuffers.Builder) { + builder.StartObject(11) +} +func StreamFinishTransactionBufferAddSize(builder *flatbuffers.Builder, size uint32) { + builder.PrependUint32Slot(0, size, 0) +} +func StreamFinishTransactionBufferAddSignature(builder *flatbuffers.Builder, signature flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(signature), 0) +} +func StreamFinishTransactionBufferStartSignatureVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamFinishTransactionBufferAddSigner(builder *flatbuffers.Builder, signer flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(signer), 0) +} +func StreamFinishTransactionBufferStartSignerVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamFinishTransactionBufferAddVersion(builder *flatbuffers.Builder, version uint32) { + builder.PrependUint32Slot(3, version, 0) +} +func StreamFinishTransactionBufferAddType(builder *flatbuffers.Builder, type_ uint16) { + builder.PrependUint16Slot(4, type_, 0) +} +func StreamFinishTransactionBufferAddMaxFee(builder *flatbuffers.Builder, maxFee flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(5, flatbuffers.UOffsetT(maxFee), 0) +} +func StreamFinishTransactionBufferStartMaxFeeVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamFinishTransactionBufferAddDeadline(builder *flatbuffers.Builder, deadline flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(6, flatbuffers.UOffsetT(deadline), 0) +} +func StreamFinishTransactionBufferStartDeadlineVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamFinishTransactionBufferAddDriveKey(builder *flatbuffers.Builder, driveKey flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(7, flatbuffers.UOffsetT(driveKey), 0) +} +func StreamFinishTransactionBufferStartDriveKeyVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamFinishTransactionBufferAddStreamId(builder *flatbuffers.Builder, streamId flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(8, flatbuffers.UOffsetT(streamId), 0) +} +func StreamFinishTransactionBufferStartStreamIdVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamFinishTransactionBufferAddActualUploadSize(builder *flatbuffers.Builder, actualUploadSize flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(9, flatbuffers.UOffsetT(actualUploadSize), 0) +} +func StreamFinishTransactionBufferStartActualUploadSizeVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamFinishTransactionBufferAddStreamStructureCdi(builder *flatbuffers.Builder, streamStructureCdi flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(10, flatbuffers.UOffsetT(streamStructureCdi), 0) +} +func StreamFinishTransactionBufferStartStreamStructureCdiVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamFinishTransactionBufferEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} From 4763c42db6ae48138998e51024f306330442dbf8 Mon Sep 17 00:00:00 2001 From: kyrylo Date: Fri, 29 Oct 2021 16:40:48 +0300 Subject: [PATCH 7/7] Stream Payment --- sdk/sdk.go | 9 + sdk/streamingv2_model.go | 7 + sdk/streamingv2_schema.go | 17 + sdk/streamingv2_transaction.go | 111 ++++++ sdk/transaction_model.go | 5 + .../schema_streamingv2_transaction.fbs | 16 +- .../streamingv2_transaction_buffer.go | 335 ++++++++++++++++++ 7 files changed, 499 insertions(+), 1 deletion(-) diff --git a/sdk/sdk.go b/sdk/sdk.go index e3b0f3a5..a2b0914e 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -945,3 +945,12 @@ func (c *Client) NewStreamFinishTransaction(deadline *Deadline, driveKey string, return tx, err } + +func (c *Client) NewStreamPaymentTransaction(deadline *Deadline, driveKey string, streamId string, additionalUploadSize StorageSize) (*StreamPaymentTransaction, error) { + tx, err := NewStreamPaymentTransaction(deadline, driveKey, streamId, additionalUploadSize, c.config.NetworkType) + if tx != nil { + c.modifyTransaction(tx) + } + + return tx, err +} diff --git a/sdk/streamingv2_model.go b/sdk/streamingv2_model.go index 0fdf8ef0..bb69d04b 100644 --- a/sdk/streamingv2_model.go +++ b/sdk/streamingv2_model.go @@ -19,3 +19,10 @@ type StreamFinishTransaction struct { ActualUploadSize StorageSize StreamStructureCdi string } + +type StreamPaymentTransaction struct { + AbstractTransaction + DriveKey string + StreamId string + AdditionalUploadSize StorageSize +} diff --git a/sdk/streamingv2_schema.go b/sdk/streamingv2_schema.go index 9b0574f7..669ed5b1 100644 --- a/sdk/streamingv2_schema.go +++ b/sdk/streamingv2_schema.go @@ -40,3 +40,20 @@ func streamFinishTransactionSchema() *schema { }, } } + +func streamPaymentTransactionSchema() *schema { + return &schema{ + []schemaAttribute{ + newScalarAttribute("size", IntSize), + newArrayAttribute("signature", ByteSize), + newArrayAttribute("signer", ByteSize), + newScalarAttribute("version", IntSize), + newScalarAttribute("type", ShortSize), + newArrayAttribute("maxFee", IntSize), + newArrayAttribute("deadline", IntSize), + newArrayAttribute("driveKey", ByteSize), + newArrayAttribute("streamId", ByteSize), + newArrayAttribute("additionalUploadSize", IntSize), + }, + } +} diff --git a/sdk/streamingv2_transaction.go b/sdk/streamingv2_transaction.go index 38143642..530d1d52 100644 --- a/sdk/streamingv2_transaction.go +++ b/sdk/streamingv2_transaction.go @@ -257,3 +257,114 @@ func (dto *streamFinishTransactionDTO) toStruct(*Hash) (Transaction, error) { dto.Tx.StreamStructureCdi, }, nil } + +func NewStreamPaymentTransaction( + deadline *Deadline, + driveKey string, + streamId string, + additionalUploadSize StorageSize, + networkType NetworkType, +) (*StreamPaymentTransaction, error) { + + tx := StreamPaymentTransaction{ + AbstractTransaction: AbstractTransaction{ + Deadline: deadline, + Version: StreamPaymentVersion, + Type: StreamPayment, + NetworkType: networkType, + }, + DriveKey: driveKey, + StreamId: streamId, + AdditionalUploadSize: additionalUploadSize, + } + + return &tx, nil +} + +func (tx *StreamPaymentTransaction) GetAbstractTransaction() *AbstractTransaction { + return &tx.AbstractTransaction +} + +func (tx *StreamPaymentTransaction) String() string { + return fmt.Sprintf( + ` + "AbstractTransaction": %s, + "DriveKey": %s, + "StreamId": %s + "AdditionalUploadSize": %d, + `, + tx.AbstractTransaction.String(), + tx.DriveKey, + tx.StreamId, + tx.AdditionalUploadSize, + ) +} + +func (tx *StreamPaymentTransaction) Bytes() ([]byte, error) { + builder := flatbuffers.NewBuilder(0) + + v, signatureV, signerV, deadlineV, fV, err := tx.AbstractTransaction.generateVectors(builder) + if err != nil { + return nil, err + } + + driveKeyB, err := hex.DecodeString(tx.DriveKey) + if err != nil { + return nil, err + } + + streamIdB, err := hex.DecodeString(tx.StreamId) + if err != nil { + return nil, err + } + + driveKeyV := transactions.TransactionBufferCreateByteVector(builder, driveKeyB) + streamIdV := transactions.TransactionBufferCreateByteVector(builder, streamIdB) + additionalUploadSizeV := transactions.TransactionBufferCreateUint32Vector(builder, tx.AdditionalUploadSize.toArray()) + + transactions.StreamPaymentTransactionBufferStart(builder) + transactions.TransactionBufferAddSize(builder, tx.Size()) + tx.AbstractTransaction.buildVectors(builder, v, signatureV, signerV, deadlineV, fV) + + transactions.StreamPaymentTransactionBufferAddDriveKey(builder, driveKeyV) + transactions.StreamPaymentTransactionBufferAddStreamId(builder, streamIdV) + transactions.StreamPaymentTransactionBufferAddAdditionalUploadSize(builder, additionalUploadSizeV) + + t := transactions.StreamPaymentTransactionBufferEnd(builder) + builder.Finish(t) + + return streamPaymentTransactionSchema().serialize(builder.FinishedBytes()), nil +} + +func (tx *StreamPaymentTransaction) Size() int { + return StreamPaymentHeaderSize +} + +type streamPaymentTransactionDTO struct { + Tx struct { + abstractTransactionDTO + DriveKey string `json:"driveKey"` + StreamId string `json:"streamId"` + AdditionalUploadSize uint64DTO `json:"additionalUploadSize"` + } `json:"transaction"` + TDto transactionInfoDTO `json:"meta"` +} + +func (dto *streamPaymentTransactionDTO) toStruct(*Hash) (Transaction, error) { + info, err := dto.TDto.toStruct() + if err != nil { + return nil, err + } + + atx, err := dto.Tx.abstractTransactionDTO.toStruct(info) + if err != nil { + return nil, err + } + + return &StreamPaymentTransaction{ + *atx, + dto.Tx.DriveKey, + dto.Tx.StreamId, + dto.Tx.AdditionalUploadSize.toStruct(), + }, nil +} diff --git a/sdk/transaction_model.go b/sdk/transaction_model.go index d8e7b0c5..143f5493 100644 --- a/sdk/transaction_model.go +++ b/sdk/transaction_model.go @@ -2789,6 +2789,7 @@ const ( DriveClosureHeaderSize = TransactionHeaderSize + KeySize StreamStartHeaderSize = TransactionHeaderSize + KeySize + StorageSizeSize + MessageSizeSize + AmountSize StreamFinishHeaderSize = TransactionHeaderSize + KeySize + Hash256 + StorageSizeSize + Hash256 + StreamPaymentHeaderSize = TransactionHeaderSize + KeySize + Hash256 + StorageSizeSize ) type EntityType uint16 @@ -2856,6 +2857,7 @@ const ( DriveClosure EntityType = 0x4E62 StreamStart EntityType = 0x4167 StreamFinish EntityType = 0x4267 + StreamPayment EntityType = 0x4367 ) func (t EntityType) String() string { @@ -2924,6 +2926,7 @@ const ( DriveClosureVersion EntityVersion = 1 StreamStartVersion EntityVersion = 1 StreamFinishVersion EntityVersion = 1 + StreamPaymentVersion EntityVersion = 1 ) type AccountLinkAction uint8 @@ -3199,6 +3202,8 @@ func MapTransaction(b *bytes.Buffer, generationHash *Hash) (Transaction, error) dto = &streamStartTransactionDTO{} case StreamFinish: dto = &streamFinishTransactionDTO{} + case StreamPayment: + dto = &streamPaymentTransactionDTO{} } return dtoToTransaction(b, dto, generationHash) diff --git a/transactions/schemas/schema_streamingv2_transaction.fbs b/transactions/schemas/schema_streamingv2_transaction.fbs index 325f59ff..7f1e5f1a 100644 --- a/transactions/schemas/schema_streamingv2_transaction.fbs +++ b/transactions/schemas/schema_streamingv2_transaction.fbs @@ -29,5 +29,19 @@ table StreamFinishTransactionBuffer { streamStructureCdi: [ubyte]; } +table StreamPaymentTransactionBuffer { + size: uint; + signature: [ubyte]; + signer: [ubyte]; + version: uint; + type: ushort; + maxFee: [uint]; + deadline: [uint]; + driveKey: [ubyte]; + streamId: [ubyte]; + additionalUploadSize: [uint]; +} + root_type StreamStartTransactionBuffer; -root_type StreamFinishTransactionBuffer; \ No newline at end of file +root_type StreamFinishTransactionBuffer; +root_type StreamPaymentTransactionBuffer; \ No newline at end of file diff --git a/transactions/streamingv2_transaction_buffer.go b/transactions/streamingv2_transaction_buffer.go index 519cc650..5758f5b4 100644 --- a/transactions/streamingv2_transaction_buffer.go +++ b/transactions/streamingv2_transaction_buffer.go @@ -762,3 +762,338 @@ func StreamFinishTransactionBufferStartStreamStructureCdiVector(builder *flatbuf func StreamFinishTransactionBufferEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } + +type StreamPaymentTransactionBuffer struct { + _tab flatbuffers.Table +} + +func GetRootAsStreamPaymentTransactionBuffer(buf []byte, offset flatbuffers.UOffsetT) *StreamPaymentTransactionBuffer { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &StreamPaymentTransactionBuffer{} + x.Init(buf, n+offset) + return x +} + +func GetSizePrefixedRootAsStreamPaymentTransactionBuffer(buf []byte, offset flatbuffers.UOffsetT) *StreamPaymentTransactionBuffer { + n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:]) + x := &StreamPaymentTransactionBuffer{} + x.Init(buf, n+offset+flatbuffers.SizeUint32) + return x +} + +func (rcv *StreamPaymentTransactionBuffer) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *StreamPaymentTransactionBuffer) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *StreamPaymentTransactionBuffer) Size() uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.GetUint32(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MutateSize(n uint32) bool { + return rcv._tab.MutateUint32Slot(4, n) +} + +func (rcv *StreamPaymentTransactionBuffer) Signature(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) SignatureLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) SignatureBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamPaymentTransactionBuffer) MutateSignature(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamPaymentTransactionBuffer) Signer(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) SignerLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) SignerBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamPaymentTransactionBuffer) MutateSigner(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamPaymentTransactionBuffer) Version() uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) + if o != 0 { + return rcv._tab.GetUint32(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MutateVersion(n uint32) bool { + return rcv._tab.MutateUint32Slot(10, n) +} + +func (rcv *StreamPaymentTransactionBuffer) Type() uint16 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(12)) + if o != 0 { + return rcv._tab.GetUint16(o + rcv._tab.Pos) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MutateType(n uint16) bool { + return rcv._tab.MutateUint16Slot(12, n) +} + +func (rcv *StreamPaymentTransactionBuffer) MaxFee(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MaxFeeLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MutateMaxFee(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(14)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamPaymentTransactionBuffer) Deadline(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) DeadlineLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MutateDeadline(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func (rcv *StreamPaymentTransactionBuffer) DriveKey(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) DriveKeyLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) DriveKeyBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamPaymentTransactionBuffer) MutateDriveKey(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamPaymentTransactionBuffer) StreamId(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) StreamIdLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) StreamIdBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + +func (rcv *StreamPaymentTransactionBuffer) MutateStreamId(j int, n byte) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) + } + return false +} + +func (rcv *StreamPaymentTransactionBuffer) AdditionalUploadSize(j int) uint32 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetUint32(a + flatbuffers.UOffsetT(j*4)) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) AdditionalUploadSizeLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func (rcv *StreamPaymentTransactionBuffer) MutateAdditionalUploadSize(j int, n uint32) bool { + o := flatbuffers.UOffsetT(rcv._tab.Offset(22)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.MutateUint32(a+flatbuffers.UOffsetT(j*4), n) + } + return false +} + +func StreamPaymentTransactionBufferStart(builder *flatbuffers.Builder) { + builder.StartObject(10) +} +func StreamPaymentTransactionBufferAddSize(builder *flatbuffers.Builder, size uint32) { + builder.PrependUint32Slot(0, size, 0) +} +func StreamPaymentTransactionBufferAddSignature(builder *flatbuffers.Builder, signature flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(signature), 0) +} +func StreamPaymentTransactionBufferStartSignatureVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamPaymentTransactionBufferAddSigner(builder *flatbuffers.Builder, signer flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(signer), 0) +} +func StreamPaymentTransactionBufferStartSignerVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamPaymentTransactionBufferAddVersion(builder *flatbuffers.Builder, version uint32) { + builder.PrependUint32Slot(3, version, 0) +} +func StreamPaymentTransactionBufferAddType(builder *flatbuffers.Builder, type_ uint16) { + builder.PrependUint16Slot(4, type_, 0) +} +func StreamPaymentTransactionBufferAddMaxFee(builder *flatbuffers.Builder, maxFee flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(5, flatbuffers.UOffsetT(maxFee), 0) +} +func StreamPaymentTransactionBufferStartMaxFeeVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamPaymentTransactionBufferAddDeadline(builder *flatbuffers.Builder, deadline flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(6, flatbuffers.UOffsetT(deadline), 0) +} +func StreamPaymentTransactionBufferStartDeadlineVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamPaymentTransactionBufferAddDriveKey(builder *flatbuffers.Builder, driveKey flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(7, flatbuffers.UOffsetT(driveKey), 0) +} +func StreamPaymentTransactionBufferStartDriveKeyVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamPaymentTransactionBufferAddStreamId(builder *flatbuffers.Builder, streamId flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(8, flatbuffers.UOffsetT(streamId), 0) +} +func StreamPaymentTransactionBufferStartStreamIdVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(1, numElems, 1) +} +func StreamPaymentTransactionBufferAddAdditionalUploadSize(builder *flatbuffers.Builder, additionalUploadSize flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(9, flatbuffers.UOffsetT(additionalUploadSize), 0) +} +func StreamPaymentTransactionBufferStartAdditionalUploadSizeVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { + return builder.StartVector(4, numElems, 4) +} +func StreamPaymentTransactionBufferEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +}