瀏覽代碼

graphql: add support for retrieving the chain id (#21451)

Shude Li 5 年之前
父節點
當前提交
341f451083
共有 2 個文件被更改,包括 6 次插入0 次删除
  1. 4 0
      graphql/graphql.go
  2. 2 0
      graphql/schema.go

+ 4 - 0
graphql/graphql.go

@@ -1044,6 +1044,10 @@ func (r *Resolver) ProtocolVersion(ctx context.Context) (int32, error) {
 	return int32(r.backend.ProtocolVersion()), nil
 }
 
+func (r *Resolver) ChainID(ctx context.Context) (hexutil.Big, error) {
+	return hexutil.Big(*r.backend.ChainConfig().ChainID), nil
+}
+
 // SyncState represents the synchronisation status returned from the `syncing` accessor.
 type SyncState struct {
 	progress ethereum.SyncProgress

+ 2 - 0
graphql/schema.go

@@ -314,6 +314,8 @@ const schema string = `
         protocolVersion: Int!
         # Syncing returns information on the current synchronisation state.
         syncing: SyncState
+        # ChainID returns the current chain ID for transaction replay protection.
+        chainID: BigInt!
     }
 
     type Mutation {