-
Notifications
You must be signed in to change notification settings - Fork 16
/
code.go
36 lines (32 loc) · 1.13 KB
/
code.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package aptos
import (
"github.com/aptos-labs/aptos-go-sdk/bcs"
)
// PublishPackagePayloadFromJsonFile publishes code created with the Aptos CLI to publish with it.
// The Aptos CLI can generate the associated file with the following CLI command:
//
// aptos move build-publish-payload
//
// metadata must be the BCS encoded metadata from the compiler, and bytecode must be the BCS encoded bytecode from the compiler.
// bytecode must be ordered in the same order out of the compiler, or it will fail on publishing.
func PublishPackagePayloadFromJsonFile(metadata []byte, bytecode [][]byte) (*TransactionPayload, error) {
metadataBytes, err := bcs.SerializeBytes(metadata)
if err != nil {
return nil, err
}
bytecodeBytes, err := bcs.SerializeSingle(func(ser *bcs.Serializer) {
bcs.SerializeSequenceWithFunction(bytecode, ser, (*bcs.Serializer).WriteBytes)
})
if err != nil {
return nil, err
}
return &TransactionPayload{Payload: &EntryFunction{
Module: ModuleId{
Address: AccountOne,
Name: "code",
},
Function: "publish_package_txn",
ArgTypes: []TypeTag{},
Args: [][]byte{metadataBytes, bytecodeBytes},
}}, nil
}